English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

i need a msg box pop-up on error and want to change the bar question, how the code should be?

If Err.Number = 3021 Then MsgBox("No record found.", vbOKOnly + vbQuestion, "Delete Message") = vbOK Else

2007-04-08 22:32:24 · 2 answers · asked by No^Point 1 in Computers & Internet Programming & Design

2 answers

You can enhance readability of your code and make it easier to see what logic you are trying to do by not cramming so much to do into one line but break it down into several steps.

Try collecting the users response from a message box into a variable. To do this you need to add the following

Dim usrInput As DialogResult

usrInput = messagebox.show("No record found.....

of course you will need to change the message box buttons from the default OK to a Yes/No. Adding the if statement you can easily see what you are trying to do. It is also easier to debug as faults will be triggered on seperate lines to help you isolate what part of the code is a problem rather than faulting on the same line with everything....

Dim usrInput As DialogResult

usrInput = messagebox.show("No record found.....

If usrInput = DialogResult.Yes Then
...your code goes here

2007-04-09 01:44:33 · answer #1 · answered by MarkG 7 · 0 0

I can't understand what you are trying to say but anyways here's an example of a code that when an error occurs, a message box will appear...

Please add a Command Button named "Command1"

On a click event...

Private Sub Command1_Click()
On Error GoTo errHandler
'Suppose we force the application to create error
Err.Raise 5
MsgBox "Continued...", vbInformation, "(^^,)"
Exit Sub
errHandler:
If MsgBox("Would you like to terminate program?", _
vbYesNo + vbQuestion, "Error") = vbYes Then
Unload Me
Else
Resume Next
End If
End Sub

2007-04-09 07:53:25 · answer #2 · answered by agent 3 · 1 0

fedest.com, questions and answers