473,513 Members | 2,425 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

OnAction executing twice

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
3 3595
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1531
by: Johan Christensson | last post by:
Hi. I'm woundering if it's possibel to transfer a OnAction value from a drop-down box in an ASP page without having to use Java code? I mean something like this: <% Sub resposeprocess
1
1697
by: acharyaks | last post by:
Hi Guru, the aspx page code executing behind the controls and functions executing twice. How can I avoid running the code behind the controls (for example this vanishes the control box text...
1
4234
by: G.Gerard | last post by:
Hello Does anyone know how to write a function name with arguments in the OnAction of a command bar button: Example: Public Sub MyFunction(strMsg as String) Msgbox strMsg
3
369
by: Paul | last post by:
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...
6
9489
by: Ken | last post by:
Please help I've been working on this for over a day. The following code will run the GetComments function from a shortcut menu. .MoveFirst Set cmb = Application.CommandBars.Add("Comments",...
4
8270
by: Vincent | last post by:
I was wondering if the CommandBarButton OnAction property would allow you to specify a function from a module to be called. According to the post made by Turtle in 1998, the OnAction property can...
7
2796
by: tshad | last post by:
I thought I understood how the SaveViewState is working and was trying to use this (as per some code I found) to detect refreshes. It seemed to be working but I found that the SaveViewState was...
1
2137
by: ApexData | last post by:
I have a ShortCutMenu that is made available on the RightClick of the mouse. The OnAction property has my custom function: =ComboBoxEditor() I believe that, in the ONAction property, I could do...
2
2588
by: grusso | last post by:
well, i need a table with all functions for onaction sentence. where i can obtain? thank yourssss
0
7264
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7166
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7386
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7543
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
5094
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3236
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3226
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
805
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
459
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.