Code triggered from Label On Click behaves differently from Command Button On Click

rich.barry

Registered User.
Local time
Today, 04:07
Joined
Aug 19, 2001
Messages
176
Often I use Labels as buttons due to the fact I can colour them the way I want, and use the on click event to trigger code.
The code below however works for a command button, but not a label button.

Code:
DoCmd.OpenForm "frmdatetime"
Do While Forms!frmdatetime!OKFlag.Caption = "False"
      DoEvents
Loop

When this code is run by clicking on a command button, it works fine.
If run by clicking on a label, frmdatetime opens, but the mouse will not work on either of the 2 open forms unless you go down to the windows task bar, jump onto another window, and back onto frmdatetime.
If I remove the loop with the DoEvents in it, then the problem does not occur.

Can anyone enlighten me as to why this behaviour occurs.

Thanks

Richard
 
i don't know - i use labels as buttons occasionally, and i recall noticing some slight difference between the behaviour of clicking lables and buttons - i can't recall exactly what it was though!

would putting a frmdatetime.setfocus help?
 
I'm sorry but I don't know either. Is there a reason you don't just use the acDialog parameter of the OpenForm command to halt your code?
 
Thanks Guys.

I had endlessly messed around with SetFocus, which did set the focus where it was told, but still would not respond to the mouse.
However opening the form with as a Dialog box is something that I had overlooked, does work, and is going to enable me to move a certain amount of rubbish from my code. I appreciate you putting me onto this option. It still doesn't explain the odd behaviour, but that no longer matters.

Cheers

Richard
 

Users who are viewing this thread

Back
Top Bottom