End If, Exit Sub problem


Posted by Rick M on July 24, 2001 5:33 AM

Here is my code:Private Sub Image2_Click()

If Sheets("customer").Range("C3") = 0 Then
MsgBox "You Must enter a Customer Name"
Range("C3").Select
End If

If Sheets("customer").Range("C5") = 0 Then
MsgBox "You Must enter a Store Name"
Range("C5").Select
End If

If Sheets("customer").Range("C7") = 0 Then
MsgBox "You Must enter an Address"
Range("C7").Select
End If


If OptionButton1 = True Then
Sheets("relamp_codes").Select
End If
If OptionButton2 = True Then
Sheets("retrofit_codes").Select
End If
If OptionButton3 = True Then
Sheets("relamp_codes").Select
End If


End Sub

What I want to do is after each MSgBox error, return to the sheet to correct the error then continue on to the next if statement. The way it is written, the code continues on without requiring the correction. If i use an exit sub, the code stops?
What am I missing?
Thanks.

Posted by Dax on July 24, 2001 5:41 AM

This works...

Private Sub Image2_Click()
If Sheets("customer").Range("C3") = "" Then
MsgBox "You Must enter a Customer Name"
Range("C3").Select
ElseIf Sheets("customer").Range("C5") = "" Then
MsgBox "You Must enter a Store Name"
Range("C5").Select
ElseIf Sheets("customer").Range("C7") = "" Then
MsgBox "You Must enter an Address"
Range("C7").Select
ElseIf OptionButton1 = True Then
Sheets("relamp_codes").Select
ElseIf OptionButton2 = True Then
Sheets("retrofit_codes").Select
ElseIf OptionButton3 = True Then
Sheets("relamp_codes").Select
End If
End Sub

HTH,
Dax.



Posted by Rick M on July 24, 2001 6:41 AM

THANKS DAX !!!!