Form as Message Box - Button Pressed

Cosmos75

Registered User.
Local time
Today, 10:07
Joined
Apr 22, 2002
Messages
1,281
I am trying to use a form in place of a msgbox.

I have a form (frmSetup) that opens another form (frmMsgBox). On frmMsgBox, I have two buttons, cmdOK & cmdCancel.

I would like to use frmMsgBox the way I would a VBA msgbox as in this example;
Code:
If MsgBox("Click somthing", vbOKCancel, "VBA MsgBox") = vbOK Then
    U_Pressed = "OK"
Else
    U_Pressed = "Cancel"
End If
But I have no idea how to pass a variable back to the code from a button click on frmMsgBox?

Anyone know how to do this or know of a post that already shows how to do this? I wasn't able to find anything.
:confused:

Attachment is Access 200 Version.
 

Attachments

Last edited:
Got help from pbaldy here. Pretty sure he is the same pbaldy as the one here!

Got it working now! THANK YOU, pbaldy!
:D
 

Attachments

Last edited:
Just to verify my own thought process on this topic, what you're doing is opening the form you want as your dialog box using acDialog as the Window Mode for in the DoCmd.OpenForm method, like:

DoCmd.OpenForm "frmMyDialog", acNormal, , , , acDialog

That suspends code execution in the module calling the DoCmd.OpenForm method.

When the custom dialog form is opened, you're writing to a public variable delclared in a standard module and closing the form from it's own code, like:

Private Sub cmdOK_Click()
publicTxt = "OK"
DoCmd.Close acForm, "frmMyDialog"
End Sub

And that re-starts code execution at the line after the DoCmd.OpenForm method.

Is that basically it? (I'm running Ac97, which is like, a ba-zillion years behind Ac2K as far as trying to open a Ac2k file from Ac97 is concerned...) :)

thanks,
 
Last edited:
I've often wondered about this but could not work out how to stop the code. :)
 
I've often wondered about this but could not work out how to stop the code.

Ya! This was the first time I'd actually tried it myself; works pretty good...

I wanted to take it one step further: have a dialog box appear during a query's execution where the query calls a custom function that opens the dialog box 'cause of some conditional in the function code. No Such Luck. Access's response: "You wanna do what? Try again later - like after you've had your head examined..." or something to that effect .

Rats!
 
Interesting that the creator has opened the form hidden and in design mode to change label titles and button names. It is far easier to assign these at run time. I took the example and added my own touches. Hope the instructions in the code explain what I am trying to achieve.

To DALeffler:

I would create a function that assigns the values and calls the MsgBox, then call this function from your query.

Dave
 

Attachments

Users who are viewing this thread

Back
Top Bottom