This is MS Access 2002. I am creating some custom buttons on a
CommandBar for a form. Below is the code. It works fine except that
the OnAction procedure is executed twice. Why? How can I fix this?
Private Sub cmdCreateTestToolBar_Click()
On Error Resume Next
CommandBars("Test Toolbar").Delete
On Error GoTo ErrorFound
Dim ctl As CommandBarControl
Call CommandBars.Add("Test Toolbar", msoBarTop, False, True)
Set ctl = CommandBars("Test Toolbar") _
.Controls.Add(msoControlButton, , , , True)
ctl.OnAction = "=Screen.ActiveForm.OnAction_Click"
ctl.Style = 2
ctl.Caption = "On Action"
CommandBars("Test Toolbar").Visible = True
ErrorFound:
If (Err.Number <> 0) Then
MsgBox "Error (" & Err.Number & ") found." _
& vbCrLf & vbCrLf & Err.Description
End If
End Sub
Private Sub OnAction_Click()
MsgBox "OnAction button was pressed from Form1."
End Sub