Double click required for cmd btn On_Click event

R

Richard S.

One of the command buttons on a form will not initiate the On_Click event
until clicked a second time.

Can anyone suggest what is needed to correct the command button function to
initiate on a single click?

Dick
 
A

Allen Browne

Double check you have used the Click event and not the DblClick event.
(Don't laugh: it happens!)

If that's not the issue, then something is preventing it from running
successfully the first time it runs. Make sure you have your error trapping
set to "Break on Unhandled Errors" (Tools | Options | General, in the code
window), and temporarily comment out any error handler.

For example, if the code does something that requires you do move record,
but the record is dirty, then that has to be solved before the code can run.
 
R

Richard S.

Allen, Thanks for the prompt response. It IS on the Click event, not the
DblClick.
The error trapping and handler are as you advised.

I'll try to make this succinct.
The form is a popup to enable entry of either of 2 search parameters: a
Member ID, or a name. Both text boxes are unbound. Upon entry of a Member
ID, the cmd btn works properly on 1 click, displaying the rec in the primary
form. However, the name entry requires a 2nd click. If there is just 1
matching name, it is displayed in the primary form (identical to the ID
search); if there are multiple matches, a secondary "index" form is displayed
pemitting navigation back-and-forth to the primary form until the "index"
form is closed. A 2nd click is necessary in either of the name search cases.

The double-click necessity would be puzzling to a user as it is to me.

I'll appreciate any further help/suggestions.
 
R

Richard S.

Further info: Both the MbrID and the name entry have the same double-click
problem. If I tab out of the text box, and the desired cmd btn is next in
the tab order, it sets focus on the btn and initiates with a single click.

What is needed to initiate the action with a single click by moving directly
to the cmd btn with the mouse and clicking it, rather than tabbing to the cmd
btn and then clicking it? (i.e., the "Cancel" cmd btn may be clicked
instead, and it of course has the same "problem".)
 
A

Allen Browne

Suggestions:

1. In the original form, I assume you have a button that opens the popup. In
this button's Click event procedure, make sure you save the current record
first. Otherwise the attempt to move record will fail. So:
If Me.Dirty Then Me.Dirty = False
DoCmd.OpenForm "MyDialog", WindowMode:=acDialog

2. On the popup the command button's click event presumably does this kind
of thing:
If Not IsNull(Me.txtMemberID) Then
'You have this working fine.
ElseIf Not IsNull(Me.txtName) Then
'This one is problematic.
Else
MsgBox "Find what???"
End If

What's the problematic code?

My personal preference to interface this is to add the unbound search boxes
to the form header (rather than a popup), as I think they are more
accessible there. The unique one (MemberID) just goes to that record
(FindFirst in form's RecordsetClone, and set Bookmark), but for the one that
could generate multiple results, I filter the form so the user can just step
through the records in this form and I don't have to build another one.

Here's a downloadable example of that interface:
http://allenbrowne.com/ser-62.html
The example is a continuous form, but I do the same in Form View. I think
you will find the code very flexible, efficient, easy to maintain, and easy
to combine multiple search options. If you don't want to download the
sample, you can read the code here:
http://allenbrowne.com/ser-62code.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top