Connecting Tech Pros Worldwide Help | Site Map

OnAction executing twice

Paul
Guest
 
Posts: n/a
#1: Nov 12 '05
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
Dimitri Furman
Guest
 
Posts: n/a
#2: Nov 12 '05

re: OnAction executing twice


On Apr 12 2004, 05:05 pm, pwh777@hotmail.com (Paul) wrote in
news:b879d94d.0404121305.3764ce13@posting.google.c om:
[color=blue]
> 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?[/color]

This has been a known bug since Access 97. The usual workaround is to
create a public function in a standard module that calls your forms'
methods, and call that public function from OnAction property.

You can also maintain a static long variable in your form's code and only
execute the code when the variable is even, then increment the variable by
1. Sometimes the bug causes it to execute three times, so you'd need to
use Mod 3.

--
remove a 9 to reply by email
Paul
Guest
 
Posts: n/a
#3: Nov 12 '05

re: OnAction executing twice


Thanks Dimitri! I had thought about using that work around, but
didn't want to. Any word on when(if) Microsoft will fix this error?
Dimitri Furman
Guest
 
Posts: n/a
#4: Nov 12 '05

re: OnAction executing twice


On Apr 13 2004, 09:41 am, pwh777@hotmail.com (Paul) wrote in
news:b879d94d.0404130541.3d073e18@posting.google.c om:
[color=blue]
> Thanks Dimitri! I had thought about using that work around, but
> didn't want to. Any word on when(if) Microsoft will fix this error?[/color]

Well, since it wasn't fixed in the last seven years, I wouldn't hold my
breath.

--
remove a 9 to reply by email
Closed Thread


Similar Microsoft Access / VBA bytes