Option Explicit

G

Guest

After being about 95% complete on my application, I realized that Option
Explicit shouldl be set on all forms. I went back and did that. Thankfully I
don't have any varibales that this affected except one. The error mssg says
the "RetValue is undeclared on the first line of the following code. Any idea
on the fix? Thanks in advance.


RetValue = MsgBox("Warning:" & vbCrLf & "Editing a Supplier Name will change
the name of all existing records for that name. Do you wish to continue?",
vbExclamation + vbYesNoCancel, "Edit Suppliers")

'If RetValue = 6 Then
'Me.AllowEdits = True 'Allow Edits To Data'
'Me.SupplierName.SetFocus 'Place cursor into FieldName'
'ElseIf RetValue = 2 Then 'Cancel Event for Cancel Button'
'DoCmd.CancelEvent
'ElseIf RetValue = 7 Then 'Cancel Event For No Button'
'DoCmd.CancelEvent
'End If
 
A

Allen Browne

Open the Immediate Window (Ctrl+G), and enter:
? Typename(MsgBox("Continue?", vbYesNoCancel))

You will see that MsgBox() returns a Long.
Therefore you need to declare:
Dim RetValue As Long

BTW, your might find it easier to understand your code if you use the
vbMsgBoxStyle constants, e.g.:
If RetValue = vbYes Then ...
You can see these values if you press F2 to open the ObjectBrowser, and
search on vbYes.

The "Select Case" construct might help too:

Select Case MsgBox("Continue?", vbYesNoCancel+vbExclamation, "Edit
Suppliers")
Case vbYes
...
Case vbNo
...
Case vbCancel
...
End Select
 
G

Guest

Thanks Allen! Works great. Appreciate it.

Allen Browne said:
Open the Immediate Window (Ctrl+G), and enter:
? Typename(MsgBox("Continue?", vbYesNoCancel))

You will see that MsgBox() returns a Long.
Therefore you need to declare:
Dim RetValue As Long

BTW, your might find it easier to understand your code if you use the
vbMsgBoxStyle constants, e.g.:
If RetValue = vbYes Then ...
You can see these values if you press F2 to open the ObjectBrowser, and
search on vbYes.

The "Select Case" construct might help too:

Select Case MsgBox("Continue?", vbYesNoCancel+vbExclamation, "Edit
Suppliers")
Case vbYes
...
Case vbNo
...
Case vbCancel
...
End Select
 

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

Similar Threads


Top