Struggling with msgbox

speakers_86

Registered User.
Local time
Today, 05:26
Joined
May 17, 2007
Messages
1,912
I haven't used error handling nor message boxes nearly enough, so I'm stumped at this. I'm not sure what the =vbOK is for, but access said it expected an equal sign, so I gave it one.


Code:
On Error GoTo Err_A
Application.FollowHyperlink "long complicated website here"
Exit Sub

Err_A:
Msgbox("Could not go to long complicated website here", vbOKOnly, "Error") = vbOK


End Sub
 
VBA expects a function to return a value if you bracket the parameters so you can have ...
Code:
Dim r as vbMsgBoxResult
[COLOR="Green"]'returns a value[/COLOR]
r = MsgBox("Really?")
... or if you don't want to return a value, don't bracket the parameters ...
Code:
MsgBox "Yeah, really."
 
Just remove the brackets if you do not want anything to happen when user presses ok.

Try :

Code:
Err_A: Msgbox "Could not go to long complicated website here", vbOKOnly, "Error"
 
What is useful is when you use the Yes/No option for the Message Box. For example putting a Command Button on a form where you are enetering some data and you want the user to check it is correct before closing.

Code:
Private Sub cmdSave_Click()

    If MsgBox("Have you Checked the Data?" & vbNewLine & vbNewLine & "Is it Correct?", vbQuestion + vbYesNo, "Check Data") = vbNo Then
        
        If MsgBox("Do you wish to Continue?" & vbNewLine & "(Form will not Close)", vbQuestion & vbYesNo, "Continue or Close") = vbYes Then
            Exit Sub
        Else
            DoCmd.Close acForm, "F-TCard"
        End If
        
    Else  ' Yes
        
        'Save Data
        DoCmd.RunCommand acCmdSaveRecord
        DoCmd.SetWarnings False
        DoCmd.OpenQuery "QA-TCard"
        DoCmd.SetWarnings True
          
        MsgBox "Data saved Successfully", vbInformation, "Closing Now"
                  
        DoCmd.Close acForm, "F-TCard"
    End If
    

End Sub
 

Users who are viewing this thread

Back
Top Bottom