Solved MsgBox Stops Detect Idle.

micks55

Registered User.
Local time
Today, 02:38
Joined
Mar 20, 2006
Messages
120
Hi All,
When a MsgBox halts execution of code it can be a good thing, you can get a Response. The downside is that my Detect Idle code (1 hour) stops counting down and my Eject Users code stops looking for a tick in the Settings table.

My problem is that one user has found that he can pick up tomorrow where he ended today just by leaving a message on screen and that makes my Detect Idle and Eject Users somewhat pointless.

Plan A. Make your own “MyMsgBox” with TempVars to return the button press but that only works with DoCmd.Open ,,,,,acDialog so this again halts the Detect Idle and Eject Users code until the MsgBox is cleared.

Plan B. Loads of great message box examples at isladogs.co.uk, thanks CR and I wish I’d seen your Detect Idle before.

Plan C. Try to understand if Isladogs message form + timer can; A) stop code execution, B) send back which button was pressed and, importantly, C) close itself after 2 minutes have passed.

Any suggestions / guidance on the best way forward would be very much appreciated.
Thanks, Mick (no longer 55, I can now see the tunnel at the end of the light)
 
When you open a form in dialog mode, code execution halts for everything else, but code execution continues for the dialog form. So, maybe using your own message box form might solve your problem.
 
Excellent observation DBguy.
I was thinking I had to avoid a Dialog form because it stops the code. But if I use a Message ‘Form’ that is a Dialog - so that it can return a value (Yes/No/Cancel) - then maybe I can use the Message Form's Timer event to close it if the user doesn’t click a button in 2 minutes.
Many Thanks, Mick.
 
Excellent observation DBguy.
I was thinking I had to avoid a Dialog form because it stops the code. But if I use a Message ‘Form’ that is a Dialog - so that it can return a value (Yes/No/Cancel) - then maybe I can use the Message Form's Timer event to close it if the user doesn’t click a button in 2 minutes.
Many Thanks, Mick.
Good luck!
 
DBguy you're a star. Tried a message form with timer 5000 and one line of code DoCmd.Close,, acSaveYes.
It closed after 5 seconds.
Tweaks to the message form are needed then I think you've cracked it.
Not looking forward to replacing 100's of instances of MsgBox with the new form but maybe Find & Replace will be possible.
Thanks again, Mick.
 
DBguy you're a star. Tried a message form with timer 5000 and one line of code DoCmd.Close,, acSaveYes.
It closed after 5 seconds.
Tweaks to the message form are needed then I think you've cracked it.
Not looking forward to replacing 100's of instances of MsgBox with the new form but maybe Find & Replace will be possible.
Thanks again, Mick.
Just as a test, try creating a public function called MsgBox() and see if it replaces the default message box function call already in your code.
 
I did use a Public Function and all has tested ok.
To test, I replaced one instance of Response = MsgBox ("The blah blah ...) with the new style Reply = MyMsgForm ("The blah blah ...) and it's correctly returning the button pressed as a string "Yes" "No" or "Cancel".
So all is good and thanks again for your 2 cents pushing me in the right direction. Just a zillion instances of MsgBox to get rid of now.
Cheers DBguy and KR Mike
 
Sub
1723824153470.png



Function
1723824304167.png
 
Perhaps you want to take a look at this "Enhaced Message Box" . It can be configured with a timer.

1723824433434.png
 
Thanks Gasman and xavier.battle. I seem to be sorted now and my Detect Idle and Eject Users code is not being interrupted when MyMsgForm replaces the standard MsgBox.
Have a good evening. Mick
 
Hi All,
When a MsgBox halts execution of code it can be a good thing, you can get a Response. The downside is that my Detect Idle code (1 hour) stops counting down and my Eject Users code stops looking for a tick in the Settings table.

My problem is that one user has found that he can pick up tomorrow where he ended today just by leaving a message on screen and that makes my Detect Idle and Eject Users somewhat pointless.

Plan A. Make your own “MyMsgBox” with TempVars to return the button press but that only works with DoCmd.Open ,,,,,acDialog so this again halts the Detect Idle and Eject Users code until the MsgBox is cleared.

Plan B. Loads of great message box examples at isladogs.co.uk, thanks CR and I wish I’d seen your Detect Idle before.

Plan C. Try to understand if Isladogs message form + timer can; A) stop code execution, B) send back which button was pressed and, importantly, C) close itself after 2 minutes have passed.

Any suggestions / guidance on the best way forward would be very much appreciated.
Thanks, Mick (no longer 55, I can now see the tunnel at the end of the light)
Do you mean ANY messagebox from any code stops your idle counter?
or do you mean that you deliberately raise a msgbox when the db is about to shut donw that they hvae to click OK to ?
 
@micks55
Thanks for your feedback
Similar to the enhanced message box, I've recently developed an autoclose message form for use with my Database Analyzer app:

This opens in dialog mode and closes automatically after a set number of seconds with the default button pressed so that the user doesn't need to sit at the screen throughout the analysis process

Here's an example:
:
1723827692041.png


Similar code is used to show a dialog message if any errors occur during the analysis
 
Hi Isaac. You prompted me to check again. I now find as follows ...
I swear it did stop the code but a standard Access MsgBox now seems to NOT stop my Detect Idle code. However, while the countdown continues and my app seems to Quit, the MsgBox remains in the middle of my desktop (and the laccdb file remains) then when I click Ok the app pops back up as if it was just hidden. It's the first time I've had that behavior so no idea why at this time.
In the past I have had an error trapped by an Err_Handler stop my Eject User code from forcing a shut down so maybe it's only "error" messages and I'm wasting everyone's time. I'll keep looking but it's getting late for an old guy.
 
Last edited:
Hi Isladogs. Excellent stuff in your web examples and I'll be spending many happy hours studying it all. I'm not a novice, started back in 1985 with an Osbourne "portable" (lol), but I'm not that skilled either and it was never my job, just a hobby. But, I am like a dog with a bone and I generally get there in the end.
Thanks again for sharing your skills.
 
Hi Isaac. Yes, any MsgBox always stops everything. For example: MsgBox "That would kill the DB!", vbOKOnly + vbCritical, "Fatal Warning" stops all code until the user clicks the Ok button to close the MsgBox. Therefore the countdown timer in my Detect Idle code in the Main form Timer event also pauses while the MsgBox is on screen. And the user has effectivly stopped me from kicking him/her out when I remote in to compress their data.
Interesting. I suppose it makes sense conceptually. Thanks for clarifying.

In my later access dev years, I took to a new method that replaced the vast majority of my messageboxes. It would be a big red notification label that would display a message for about 5 seconds, then disappear. I can't remember if stuff like this was one of the reasons why I initially decided to go that direction but maybe. I just liked it because it's one less thing for the user to have to click on - or accidentally hurriedly disposition by flying too fast on the Enter key and miss the message. Just a thought to tuck away in case it's useful.
The nice thing is you can write a Sub that does this over and over and just call it like DisplayBanner "something", 5
 
I wanted to check to see if I had my facts correct so I went back to an earlier copy of the FE which uses the inbuilt Access MsgBox extensively.

I open frmMain (the start up form with Form_Timer “Detect Idle” code). Two temporary controls are visible: ActiveForm shows “frmMain” and IdleTime is incrementing at 2 sec intervals.

I go to (open) frmQuote and move it so I can see frmMain behind where ActiveForm now shows “frmQuote” and IdleTime has reset and started incrementing again.

In frmQuote I click on a button and a MsgBox asks a question. If I click theMsgBox Ok button the MsgBox clears and when the timer has reached it’s limit the frmMain Timer event code Application.Quit acQuitSaveAll causes the application to quit and the laccdb file is removed.

If I do NOT click the MsgBox Ok button so the MsgBox remains on screen. When Application.Quit acQuitSaveAll is triggered it causes the app to minimise and leaves the MsgBox floating in the middle of the desktop. The laccdb is not removed and when I click Ok in the MsgBox floating on my desktop the app is restored.

If anyone can replicate or explain this it might help others. I'm just going to get rid of all MsgBox's and use my own form.
Thanks again to all that have contributed.
 
I think I have demonstrated that if you have your own function called MSGBOX, then that takes precedence over the built in MSGBOX?
So all you have to do is display your form in that function and return the appropriate value that the builtin function does.

No need to replace anything?
 
Great tip, Gasman. Thanks for mentioning that a Function called MsgBox would take precedence over the Access MsgBox.
I did as you suggested and created a Function called MsgBox.
eg: Public Function MsgBox(Prompt As String, Optional Buttons, Optional Title As String)
I found the inbuilt button values on MS website eg: vbYesNo (4) + vbCritical (16) = 20 so vbYesNo etc. didn't need editing.
I then kept trying Debug to locate problems and edited them.
A few errors popped up consistently.
Can’t build a MsgBox prompt string with eg: Dim MyMsgTxt you must use Dim MyMsgTxt As String
Can’t use If Response = vbNo, must use If Response = “No” (my buttons return text).
Can’t use the simple MsgBox Err.Description. I commented them and will sort all of the Err_Handlers later.
I'm still checking and fixing odds and ends but Find/Replace did an awful lot of it so not far to go.
The best part is that the Detect Idle code works as intended because it’s now a form rather than an Access MsgBox.
Thanks again Gasman.
 
Great tip, Gasman. Thanks for mentioning that a Function called MsgBox would take precedence over the Access MsgBox.
I did as you suggested and created a Function called MsgBox.
eg: Public Function MsgBox(Prompt As String, Optional Buttons, Optional Title As String)
I found the inbuilt button values on MS website eg: vbYesNo (4) + vbCritical (16) = 20 so vbYesNo etc. didn't need editing.
I then kept trying Debug to locate problems and edited them.
A few errors popped up consistently.
Can’t build a MsgBox prompt string with eg: Dim MyMsgTxt you must use Dim MyMsgTxt As String
Can’t use If Response = vbNo, must use If Response = “No” (my buttons return text).
Can’t use the simple MsgBox Err.Description. I commented them and will sort all of the Err_Handlers later.
I'm still checking and fixing odds and ends but Find/Replace did an awful lot of it so not far to go.
The best part is that the Detect Idle code works as intended because it’s now a form rather than an Access MsgBox.
Thanks again Gasman.
I guess you might have missed my comment in post #6. :)
 
I guess you might have missed my comment in post #6. :)
@theDBguy it was from your suggestion that I tried it out. :)
 

Users who are viewing this thread

Back
Top Bottom