在右键单击CommandBar菜单上获取当前记录

时间:2019-04-02 21:50:30

标签: ms-access

我试图在右键CommandBar菜单(上下文菜单)上获取当前记录ID,以打开链接的报告。我致力于MS-ACCESS 2013

我尝试使用以下代码(Open Current Record from Right-Click CommandBar Menu),但我总是得到多列而不是活动列的第一个ID。

这是表格代码

Private Sub Form_Load()
     CreateFormShortcutMenu_EmployePayList
End Sub


Private Sub CreateFormShortcutMenu_EmployePayList()

    Dim sMenuName As String
    sMenuName = "cmdShortCutMenu_EmployePayList"

    On Error Resume Next
    CommandBars(sMenuName).Delete
    If Err.Number <> 0 Then Err.Clear
    On Error GoTo 0

    Dim cmbRightClick As Office.CommandBar
    Dim cmbControl As Office.CommandBarControl

    Set cmbRightClick = CommandBars.Add(sMenuName, msoBarPopup, False, False)

    With cmbRightClick

        Set cmbControl = .Controls.Add(msoControlButton, 539, , , True)
        cmbControl.Caption = "New record"

        Set cmbControl = .Controls.Add(msoControlButton, 644, , , True)
        cmbControl.Caption = "Delete record"

        ' Add the Copy command
        Set cmbControl = .Controls.Add(msoControlButton, 19, , , True)
        cmbControl.Caption = "Copy"
        cmbControl.BeginGroup = True

        ' Add the Copy command
        Set cmbControl = .Controls.Add(msoControlButton, 22, , , True)
        cmbControl.Caption = "Paste"

        ' Add View TicketPay command
        Set cmbControl = .Controls.Add(msoControlButton, , , , True)
        With cmbControl
            .BeginGroup = True
            .Caption = "Ticket pay"
            .Parameter = Me.IdPay
            .OnAction = "=CallbackOpenTicketPay()"
            .FaceId = 65
        End With

    End With

    Me.ShortcutMenu = True
    Me.ShortcutMenuBar = sMenuName

    Set cmbControl = Nothing
    Set cmbRightClick = Nothing

End Sub 

这是回调函数的代码(在单独的模块中)

Option Compare Database
Option Explicit

Public Function CallbackOpenTicketPay()
    Dim cbar As CommandBarControl

    Set cbar = CommandBars.ActionControl
    If cbar Is Nothing Then
        Debug.Print "CBar is nothing"
        Exit Function
    End If

    Dim IdPay
    IdPay = cbar.Parameter

    MsgBox IdPay
    MsgBox Screen.ActiveForm.ActiveControl.Form.IdPay

End Function

第一个消息框返回子窗体中显示的第一个记录ID。 我可以通过第二个电话找到替代方法,但我不明白为什么第一个电话不起作用。

0 个答案:

没有答案