Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ms access 表字段说明-MS访问_Ms Access_Properties - Fatal编程技术网

Ms access 表字段说明-MS访问

Ms access 表字段说明-MS访问,ms-access,properties,Ms Access,Properties,我环顾四周,发现了一些VBA代码,介绍了如何从字段的“描述”框中获取描述,而不是如何在表单属性中使用该描述 我希望有一个ControlTip,其中包含从数据库中的描述中获取的字段描述,而不必重写所有描述;我希望有一个复制粘贴的代码,我可以添加到所有的控件提示位 类似(但显然不是) 有人知道密码吗,或者即使有密码 编辑: 以上内容用于显示状态栏文本。然而,我想用活动窗体填充“frmTrials”,用当前活动控件填充“txtBox”;这样,当控件激活时,我可以将StatusBarText放入“描述框

我环顾四周,发现了一些VBA代码,介绍了如何从字段的“描述”框中获取描述,而不是如何在表单属性中使用该描述

我希望有一个ControlTip,其中包含从数据库中的描述中获取的字段描述,而不必重写所有描述;我希望有一个复制粘贴的代码,我可以添加到所有的控件提示位

类似(但显然不是)

有人知道密码吗,或者即使有密码

编辑:

以上内容用于显示状态栏文本。然而,我想用活动窗体填充“frmTrials”,用当前活动控件填充“txtBox”;这样,当控件激活时,我可以将StatusBarText放入“描述框”文本字段(或控件提示等)。我试过了


这就给我带来了错误。

您可以尝试使用它的一种变体,遍历表单上的所有控件,并将其工具提示设置为与绑定数据源匹配的任何字段

Private子表单_Load()
'加载当前窗体的工具提示'
'同时将其放置在所有子窗体中'
设置工具提示我
'如果窗体在运行时绑定,则可以调用use代替'
设置工具提示我,myDataRecordSet
端接头
私有子集合工具提示(frm作为表单,可选rs作为dao.Recordset)
Dim CTL作为控件
Dim-ctl作为对照
将源字段设置为字符串
以字符串形式显示的模糊描述
出错时继续下一步
设置ctls=frm.控件
如果rs为空,则设置rs=frm.Recordset
对于ctl中的每个ctl
sourceField=ctl.ControlSource
如果Len(sourceField)>0,则
description=rs.Fields(sourceField).Properties(“description”)
如果Len(描述)>0,则
ctl.ControlTipText=说明
如果结束
如果结束
下一个ctl
设置ctls=Nothing
端接头

据我所知,您希望在每次加载表单时动态设置
ControlTipText
属性。由于您在注释中指出此应用程序适用于平板电脑设备,因此在打开表单时,您可能希望限制处理器负载。您可以通过将
ControlTiptText
属性与表单的设计一起保存来实现这一点

使用表单名称尝试以下过程,如下所示:

SetControlTipText "YourFormName"
程序如下。我在有限的测试中没有发现任何问题。它为复选框、组合框、列表框和文本框设置
ControlTiptText
。更改第一个
案例
行以针对不同的控件集

Public Sub SetControlTipText(ByVal pFormName As String)
    Dim ctl As Control
    Dim db As DAO.Database
    Dim frm As Form
    Dim rs As DAO.Recordset

    DoCmd.OpenForm pFormName, acDesign
    Set frm = Forms(pFormName)
    If Len(frm.RecordSource) > 0 Then
        Set db = CurrentDb
        Set rs = db.OpenRecordset(frm.RecordSource)
        For Each ctl In frm.Controls
            Select Case ctl.ControlType
            Case acCheckBox, acComboBox, acListBox, acTextBox
                If Len(ctl.ControlSource) > 0 _
                        And Not ctl.ControlSource Like "=*" Then
                    ctl.ControlTipText = _
                        GetDescription(rs.Fields(ctl.ControlSource))
                End If
            Case Else
                ' pass '
            End Select
        Next ctl
        rs.Close
    End If
    Set ctl = Nothing
    Set rs = Nothing
    Set db = Nothing
    Set frm = Nothing
    DoCmd.Close acForm, pFormName, acSaveYes
End Sub
SetControlTipText
调用此函数:

Public Function GetDescription(ByRef pObject As Object) As String
    Dim strReturn As String

On Error GoTo ErrorHandler

    strReturn = pObject.Properties("Description")

ExitHere:
    GetDescription = strReturn
    On Error GoTo 0
    Exit Function

ErrorHandler:
    strReturn = vbNullString ' make it explicit '
    GoTo ExitHere
End Function
setControlTiptText
过程忽略未绑定的表单。如果绑定字段的控件源未分配
说明
属性,则其
ControlTipText
将设置为空字符串

这种方法将要求您为表单运行一次该过程,而不是在每次加载表单时运行其他过程。如果以后更改任何窗体记录源字段的
Description
属性,可以重新运行
setControlTiptText
以更新
ControlTiptText

或者,您可以对所有应用程序的表单运行该过程,作为发布新版本应用程序的准备工作的一部分

Dim frm As Object
For Each frm in CurrentProject.AllForms
    SetControlTipText frm.Name
Next frm

最后使用文本字段来显示说明,而不是控件提示。我也有一张资料性的照片出现(如果在给定的文件夹中有一张这样命名的照片)。我应该注意的是,我没有对非PNG格式的图像进行任何处理,尽管我确信可以添加

Public Function pushInfo(frm As Form)
'On Error Resume Next
Dim desc As String 'description from the status bar of the active control
Dim path As String 'path to image
Dim dbPath As String 'path to the database
Dim hyperPath As String 'path to hyperlink

'Take the statusbar text and push it into the description box caption.
desc = Forms(frm.Name).Controls(frm.ActiveControl.Name).StatusBarText 'Put statusbar text into var "desc"
frm.txtInfo.Caption = vbNewLine & vbNewLine & desc 'Put the text (with linefeeds) into the box
frm.lblInfo.Caption = frm.ActiveControl.Name & " Description:" 'Put the database name of the field into the label

'Set the image in the imgbox
dbPath = Left(CurrentDb.Name, InStrRev(CurrentDb.Name, "\"))   'path to the DB.
path = dbPath & "img\" 'add the img directory
path = path & frm.Name & "\" 'add the form name
path = path & frm.ActiveControl.Name 'add the control's name
path = path & ".png" 'add the jpg suffix
hyperPath = path

If (Len(Dir(path)) = 0) Then 'if the image doesn't exist (this field has no image..)
    path = dbPath & "img\GenericLogo.png" 'set to the logo
    hyperPath = ""
End If

Forms(frm.Name).Controls("imgInfo").Picture = path 'set the picture to the defined path
Forms(frm.Name).Controls("imgInfo").HyperlinkAddress = hyperPath 'set the picture to link to the file
End Function

描述通常出现在状态栏中,您也希望它出现在控制提示中?我仍然不明白用户为什么希望控制提示也出现在状态栏中。控制提示可能很烦人。@Remou同意,但这可能是开发人员无法控制的要求。我计划将其作为平板电脑可访问的东西推出,因此我使用我的窗体作为弹出类型,以最小化屏幕空间;用状态栏打开整个程序太过分了。加上一些有非常长,非常必要的描述,所以如果我可以设置它的控制技巧,我可以设置它的任何东西(制作动态描述框等),这是一个非常优雅,很好的代码。谢谢我现在就试试。@user1394459该代码严重依赖于下一步错误恢复时的
功能。只有可以绑定数据的控件才具有
ControlSource
。类似地,如果
sourceField
包含类似
=[Price]*[Quantity]
的语句,则
.Fields(sourceField)
可能无效。在这种情况下,代码将失败,但它将恢复到下一行,而不是显示错误。所以我们基本上可以忽略这些错误,因为它们不会为我们的工具提示生成任何数据。标记为答案,因为我相信它回答了我最初的问题。我最终选择了另一个方向(当鼠标移到控件上时会填充一个文本字段),所以我没有对此进行测试,但是它确实给了我一些我实现的变量/方法。
Public Function GetDescription(ByRef pObject As Object) As String
    Dim strReturn As String

On Error GoTo ErrorHandler

    strReturn = pObject.Properties("Description")

ExitHere:
    GetDescription = strReturn
    On Error GoTo 0
    Exit Function

ErrorHandler:
    strReturn = vbNullString ' make it explicit '
    GoTo ExitHere
End Function
Dim frm As Object
For Each frm in CurrentProject.AllForms
    SetControlTipText frm.Name
Next frm
Public Function pushInfo(frm As Form)
'On Error Resume Next
Dim desc As String 'description from the status bar of the active control
Dim path As String 'path to image
Dim dbPath As String 'path to the database
Dim hyperPath As String 'path to hyperlink

'Take the statusbar text and push it into the description box caption.
desc = Forms(frm.Name).Controls(frm.ActiveControl.Name).StatusBarText 'Put statusbar text into var "desc"
frm.txtInfo.Caption = vbNewLine & vbNewLine & desc 'Put the text (with linefeeds) into the box
frm.lblInfo.Caption = frm.ActiveControl.Name & " Description:" 'Put the database name of the field into the label

'Set the image in the imgbox
dbPath = Left(CurrentDb.Name, InStrRev(CurrentDb.Name, "\"))   'path to the DB.
path = dbPath & "img\" 'add the img directory
path = path & frm.Name & "\" 'add the form name
path = path & frm.ActiveControl.Name 'add the control's name
path = path & ".png" 'add the jpg suffix
hyperPath = path

If (Len(Dir(path)) = 0) Then 'if the image doesn't exist (this field has no image..)
    path = dbPath & "img\GenericLogo.png" 'set to the logo
    hyperPath = ""
End If

Forms(frm.Name).Controls("imgInfo").Picture = path 'set the picture to the defined path
Forms(frm.Name).Controls("imgInfo").HyperlinkAddress = hyperPath 'set the picture to link to the file
End Function