I
injanib via AccessMonster.com
In the procedure below I keep getting error saying "Else without if" and the
debug points to the "Else" statement I have underlined.
If I remove the first two "if" statements which is for the Null fields, then
the problem goes away.
I can't figure out what I need to add or remove.
Private Sub cmdModify_Click()
Dim intResponse As Integer
If Me.cmdModify.Caption = "Save" Then
If IsNull(Me.Contact) Then
MsgBox ("Contact name is required."), vbCritical + vbOKOnly
Me.Contact.SetFocus
Else
If IsNull(Me.Email) Then
MsgBox ("Email address is required."), vbCritical + vbOKOnly
Me.Email.SetFocus
Else
If Me.NewRecord Then
intResponse = MsgBox("Are you sure you want to save this new
customer?", vbQuestion + vbYesNo, "Save Record?")
Else
intResponse = MsgBox("Are you sure you want to save the changes?",
vbQuestion + vbYesNo, "Save Changes?")
End If
If intResponse = vbNo Then
Me.Undo
Else
Me.Dirty = False
Me.cmdNext.Enabled = True
Me.Contact.Locked = True
Me.Company.Locked = True
Me.Cell.Locked = True
Me.Email.Locked = True
Me.Address.Locked = True
Me.cmdDelete.Enabled = False
Me.cmdModify.Caption = "Modify"
End If
Else
------
If Me.cmdModify.Caption = "Modify" Then
Me.Contact.Locked = False
Me.Company.Locked = False
Me.Cell.Locked = False
Me.Email.Locked = False
Me.Address.Locked = False
Me.cmdModify.Caption = "Save"
Me.cmdDelete.Enabled = True
End If
End If
End Sub
debug points to the "Else" statement I have underlined.
If I remove the first two "if" statements which is for the Null fields, then
the problem goes away.
I can't figure out what I need to add or remove.
Private Sub cmdModify_Click()
Dim intResponse As Integer
If Me.cmdModify.Caption = "Save" Then
If IsNull(Me.Contact) Then
MsgBox ("Contact name is required."), vbCritical + vbOKOnly
Me.Contact.SetFocus
Else
If IsNull(Me.Email) Then
MsgBox ("Email address is required."), vbCritical + vbOKOnly
Me.Email.SetFocus
Else
If Me.NewRecord Then
intResponse = MsgBox("Are you sure you want to save this new
customer?", vbQuestion + vbYesNo, "Save Record?")
Else
intResponse = MsgBox("Are you sure you want to save the changes?",
vbQuestion + vbYesNo, "Save Changes?")
End If
If intResponse = vbNo Then
Me.Undo
Else
Me.Dirty = False
Me.cmdNext.Enabled = True
Me.Contact.Locked = True
Me.Company.Locked = True
Me.Cell.Locked = True
Me.Email.Locked = True
Me.Address.Locked = True
Me.cmdDelete.Enabled = False
Me.cmdModify.Caption = "Modify"
End If
Else
------
If Me.cmdModify.Caption = "Modify" Then
Me.Contact.Locked = False
Me.Company.Locked = False
Me.Cell.Locked = False
Me.Email.Locked = False
Me.Address.Locked = False
Me.cmdModify.Caption = "Save"
Me.cmdDelete.Enabled = True
End If
End If
End Sub