【问题标题】:MS Access Caption Assigned ButtonMS Access 字幕分配按钮
【发布时间】:2013-03-22 23:07:12
【问题描述】:

我正在尝试在 MS Access 的“代码生成器”部分中编写代码,该代码将从记录中的按钮中提取标题。我有一个名为 Main Menu 的表,其中包括字段“ RecordID、Caption 和 Report to Run。我需要此按钮根据 MainMenu 表中的标题名称为其分配标题。

例如。按钮 A(记录 ID = 1,标题 = 借款人,要运行的报告 = rptCurrentBorrowers)。

点击后,我需要此按钮的标题 = 借款人,方法是从按钮 A 的记录中读取标题。我无法在需要从 MainMenu 表中拉出的按钮中专门写下标题。

【问题讨论】:

    标签: database ms-access button dao caption


    【解决方案1】:

    我的猜测是,此表单正在显示来自其他表的记录,当您浏览这些记录时,您希望按钮标题根据在 [Main Menu] 表上的查找来更改。

    如果是这样,那么在该表单 (Sub Form_Current()) 的 On Current 事件中类似以下的语句可能会起作用:

    me.Button_A.Caption = DLookup("Caption", "Main Menu", "RecordID=" & me.RecordID.Value)
    

    【讨论】:

    • Gord,只是为了跟进你在这里给我的内容。这为我的代码指明了正确的方向,并使我能够完成代码。我现在可以根据表格中的记录为按钮分配标题。
    【解决方案2】:

    戈德·汤普森(Gord Thompson)为我指出了正确的位置。因此,在进行了大量研究之后,我不仅发现了如何实现这种类型的代码,而且发现了它为什么有用。 DLookup 只需在数据库中搜索记录或查询,然后根据其标准将信息拉入其脚本位置。我需要为按钮标题实现此功能的原因是,我的最终用户能够从表格中更改按钮的标题,而不是操纵实际代码。这是我完成的 VBA 代码,带有工作按钮。

    Private Sub Form_Open(Cancel As Integer)
        rptBorrower.Caption = DLookup("Caption", "MainMenu", "ReportID = 1")
        rptMediaList.Caption = DLookup("Caption", "MainMenu", "ReportID = 2")
        rptPastDue.Caption = DLookup("Caption", "MainMenu", "ReportID = 3")
    End Sub
    
    
    '' This code defines the Borrower Button
    Private Sub rptBorrower_Click()
        rptBorrower.Caption = DLookup("Caption", "MainMenu", "ReportID = 1")
    
        Dim varBorrower As Variant
        varBorrower = DLookup("[ReportToRun]", "MainMenu", "[ReportID] = 1")
        DoCmd.OpenReport varBorrower, acViewReport
    
        rptBorrower_Click_Exit:
        Exit Sub
    End Sub
    
    '' This code is defines the Media List Button
    
    Private Sub rptMediaList_Click()
        rptMediaList.Caption = DLookup("Caption", "MainMenu", "ReportID = 2")
    
        Dim varMediaList As Variant
        varMediaList = DLookup("[ReportToRun]", "MainMenu", "[ReportID] = 2")
        DoCmd.OpenReport varMediaList, acViewReport
    
        rptMediaList_Click_Exit:
        Exit Sub
    End Sub
    
    '' This code defines the Past Due Report Button
    
    Private Sub rptPastDue_Click()
        rptPastDue.Caption = DLookup("Caption", "MainMenu", "ReportID = 3")
    
        Dim varPastDue As Variant
        varPastDue = DLookup("[ReportToRun]", "MainMenu", "[ReportID] = 3")
        DoCmd.OpenReport varPastDue, acViewReport
    
        rptPastDue_Click_Exit:
        Exit Sub
    End Sub
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多