MsgBox returned value

G

Guest

I have a MsgBox and cannot tell which button was pressed. Based on that value, I want to be able to exit an [Event Procedure]. Here is the piece of code that brings up the box

Private Sub UpdateAccruedLeaveTime_Click(
On Error GoTo Err_UpdateAccruedLeaveTime_Clic

' make sure they want to do it
Dim strMsg As String, strTitle As Strin
Dim intStyle As Intege

strMsg = "This action will update ALL records. Is that what you want?
intStyle = vbYesN
strTitle = "* * * Update Records * * *
MsgBox strMsg, intStyle, strTitl


Dim stDocName As Strin

stDocName = "qryUpdateAnnualBal
DoCmd.OpenQuery stDocName, acNormal, acEdi

Regardless of the Yes or No button pressed, intStyle always returns a value of 4.

tia
JMorrell
 
R

Rodrigo

Try this

if vbNo= MsgBox (strMsg, intStyle, strTitle) then
exit sub
end if
Rodrigo.

JMorrell said:
I have a MsgBox and cannot tell which button was pressed. Based on that
value, I want to be able to exit an [Event Procedure]. Here is the piece of
code that brings up the box:
Private Sub UpdateAccruedLeaveTime_Click()
On Error GoTo Err_UpdateAccruedLeaveTime_Click

' make sure they want to do it.
Dim strMsg As String, strTitle As String
Dim intStyle As Integer

strMsg = "This action will update ALL records. Is that what you want?"
intStyle = vbYesNo
strTitle = "* * * Update Records * * *"

if vbNo= MsgBox (strMsg, intStyle, strTitle) then
exit sub
end if
 
J

Joan Wild

You need to use the MsgBox function, not the MsgBox statement

If MsgBox(strMsg, intStyle, strTitle) = vbYes Then
CurrentDB.Execute "qryUpdateAnnualBal", dbFailOnError
End if


--
Joan Wild
Microsoft Access MVP

JMorrell said:
I have a MsgBox and cannot tell which button was pressed. Based on that
value, I want to be able to exit an [Event Procedure]. Here is the piece of
code that brings up the box:
 
R

Rodrigo

From the help

"Displays a message in a dialog box, waits for the user to click a button,
and returns an Integer indicating which button the user clicked."

They are both the same thing. Basically if you want to show a mesage and
don't care what the user responds al you do is
msgbox "this is just at test"
(you can add a title, etc if you want)

But if you care what the user responds then:
sub test()
' I usually put the expected responce in the front, it makes things easier
to read
'Just make sure the expected responce is part of the msgbox return arguments
(if you are expecting vbNo, make sure you 'have a vbNO, or VbYesNo as part
of the msgbox arguments)

if vbNo = msgbox("Are you sure you want to quit",vbYesNo,"Quit?")
exit sub
end if
DoCmd.Quit acQuitSaveNone
end if

Rodrigo.


JMorrell said:
Thanks for the distinction. I've never used the MsgBox function and can't
find an example of it in the Northwind db. Can you tell me how it differs
and the correct way to use it?
 

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