Reputation:
This is a basic question, but I haven't found any solutions after a Google search.
Here's what I'm trying to do:
I can't get the MsgBox to launch properly: it's highlighted in red. I think this is a syntax issue.
Sub DataProcessingExperiment7
On Error GoTo ErrorHandler
...
ErrorHandler
MsgBox("Error detected" & vbNewLine & "Error" & Err.Number & ": " & Err.Description, vbCritical, "Error Handler: Error" & Err.Number, , , asVbMsgBoxResult)
Upvotes: 0
Views: 4937
Reputation: 2953
If you just want to show the user a message with an ok button then use:
MsgBox "This is the message", vbCritical, "This is the title"
The only bit you need is the message bit. You can use named parameters, like this (makes it easier to know which bit is what):
MsgBox Prompt:="This is the message", Buttons:=vbCritical, Title:="This is the title"
If you want to give the user a Yes/No, Ok/Cancel choice, then you use MsgBox as a function and store or use the result.
If vbNo = MsgBox(Prompt:="Do you want to continue?",Buttons:=vbQuestion + vbYesNo, Title:="Are you sure?") Then
For your code use:
ErrorHandler:
MsgBox Prompt:="Error detected" & vbNewLine & "Error" & Err.Number & ": " & Err.Description, Buttons:=vbCritical, Title:="Error Handler: Error" & Err.Number
Upvotes: 0
Reputation: 1377
You call shouldn't be in parenthesis (brackets) unless you're wanting to return a value. Remove the brackets after msgbox
Sub DataProcessingExperiment7
On Error GoTo ErrorHandler
...
ErrorHandler:
MsgBox "Error detected" & vbNewLine & "Error" & Err.Number & ": " & Err.Description, vbCritical, "Error Handler: Error" & Err.Number, ,
Edit:
And you have too many arguments. Remove one
Upvotes: 1