Solved Custom Message Box Strange Behavior and error [I need Help]

mloucel

Member
Local time
Today, 08:40
Joined
Aug 5, 2020
Messages
267
Hello Gurus:

Thru trial and error, and with lots of help from many of you here and some other places in the Access world, I was able to proudly create my own message box.

While I thought it was working fine, I found out that was actually failing with a strange behavior I was not aware, so I went to TEST mode and try to check why things were happening, and thou I used a LOT of msgbox to try the code in different parts I cannot figure out what is wrong.

I created a test DB [here attached] where I can show you my issue:

I start with the form frmTest
this one has only 1 button "Test", which then, creates all the parameters to create the Custom MB, I have an important variable called Resp defined as STRING, which will hold the value of the button pressed in the message box, [B1 or B2] this ones can change to Yes/No, Accept/Reject, Continue/Return, etc, it doesn't matter what I display in them at the end is either B1 or B2, I need to check.

This open then MMB [My Message Box], this one then Loads all the Arguments, and determines if B2 has a value or is = to NS, if the value is NS then that button is NOT displayed and button 1 is centered in the form.

HERE IS HE PROBLEM..

It should stop right here, waiting for a button to be pressed, to continue carrying the value of the pressed Button, but it doesn't WAIT and I have no idea why ..


Best is if you can see what I mean.

Please kindly check my Test DB and let me know what is my error.
{DISCLAIMER} I HAD A LOT OF THINGS STRIPPED AWAY AND SOME OF ACKNOWLEDGEMENT OF AUTHOR OF THE CODE WAS DELETED TO HELP ME REDUCE THE SIZE.

Thanks.

Maurice.
 

Attachments

If you want code execution to pause while a form is open, you need to open that form with the acDialog window mode switch. Edit your line of code that opens the form to be...
Code:
DoCmd.OpenForm "MessageBoxF", , , , , acDialog, Args
 
I changed your code to what mark posted but still got errors (but not due to marks code, that's correct)

I had to change the datatype returned by your function MMB to a variant and then it seemed to work correctly.
With the exception of your second msgbox which I think you only wanted the OK button to show but both buttons are showing.

edit: I had to look at a fresh copy of your db and noted that you had MMB returning a long but it should have been a string. That's why variant worked.
 
Last edited:
you may also try this:
Thanks @arnelgp I see my blunder(s) now, thanks, I hope as well this code helps someone else, is simple, yet it works, I'll disclose all the authors in the code so they can be properly identified.

Maurice.
 
I changed your code to what mark posted but still got errors (but not due to marks code, that's correct)

I had to change the datatype returned by your function MMB to a variant and then it seemed to work correctly.
With the exception of your second msgbox which I think you only wanted the OK button to show but both buttons are showing.

edit: I had to look at a fresh copy of your db and noted that you had MMB returning a long but it should have been a string. That's why variant worked.
Thanks, please kindly check the code that @arnelgp corrected, it works perfectly, maybe it will be of use to you.
 
If you want code execution to pause while a form is open, you need to open that form with the acDialog window mode switch. Edit your line of code that opens the form to be...
Code:
DoCmd.OpenForm "MessageBoxF", , , , , acDialog, Args
Thanks, please kindly check the code that @arnelgp corrected, it works perfectly, maybe it will be of use to you.
 

Users who are viewing this thread

Back
Top Bottom