By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,412 Members | 2,882 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,412 IT Pros & Developers. It's quick & easy.

OnAction executing twice

P: n/a
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
Nov 12 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Apr 12 2004, 05:05 pm, pw****@hotmail.com (Paul) wrote in
news:b8**************************@posting.google.c om:
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?


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
Nov 12 '05 #2

P: n/a
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?
Nov 12 '05 #3

P: n/a
On Apr 13 2004, 09:41 am, pw****@hotmail.com (Paul) wrote in
news:b8**************************@posting.google.c om:
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?


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

--
remove a 9 to reply by email
Nov 12 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.