Sandra Smith
asked on
Message box cancel NOT working
I have the following code which should prevent a user from saving the record if all of the product checkboxes are empty-they must select one-but is isn't working correctly. Thanks and appreciate any help
Private Sub cmdSave_Click()
On Error GoTo Err_cmdSave_Click
If IsNull(Me.SPC) And IsNull(Me.SPS) And IsNull(Me.CheckFree) And IsNull(SCS) And IsNull(SIM) Then
MsgBox "You must select a Product Type", vbCancel
vbCancel = True
Else
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.Close
Exit_cmdSave_Click:
Exit Sub
End If
Err_cmdSave_Click:
MsgBox Err.Description
Resume Exit_cmdSave_Click
End Sub
Private Sub cmdSave_Click()
On Error GoTo Err_cmdSave_Click
If IsNull(Me.SPC) And IsNull(Me.SPS) And IsNull(Me.CheckFree) And IsNull(SCS) And IsNull(SIM) Then
MsgBox "You must select a Product Type", vbCancel
vbCancel = True
Else
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.Close
Exit_cmdSave_Click:
Exit Sub
End If
Err_cmdSave_Click:
MsgBox Err.Description
Resume Exit_cmdSave_Click
End Sub
ASKER
Thanks for the suggestion and I just relaized something. The IsNull may not work as the six boxes are checkboxes and as my husband stands here yelling at me. I am totally confused about the syntax of using checkboxes. I tried the below for just one checkbox, but it does not work either.
Private Sub Form_Close()
On Error GoTo Err_cmdSave_Click
If Me.SPC.Checkboxes.Checked = False Then
'if its all null then just exit out of the function to give them another shot!
MsgBox "You must select a Product Type", vbOKOnly, "Error"
DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
Else
'success
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.Close
Exit Sub
End If
Err_cmdSave_Click:
MsgBox Err.Description
End Sub
Private Sub Form_Close()
On Error GoTo Err_cmdSave_Click
If Me.SPC.Checkboxes.Checked = False Then
'if its all null then just exit out of the function to give them another shot!
MsgBox "You must select a Product Type", vbOKOnly, "Error"
DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
Else
'success
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.Close
Exit Sub
End If
Err_cmdSave_Click:
MsgBox Err.Description
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Private Sub Form_Close()
On Error GoTo Err_cmdSave_Click
If Not (SPC.Checked And SPS.Checked And CheckFree.Checked And SCS.Checked And SIM.Checked) Then
'if its all null then just exit out of the function to give them another shot!
MsgBox "You must select a Product Type", vbOKOnly, "Error"
DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
Else
'success
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.Close
Exit Sub
End If
Err_cmdSave_Click:
MsgBox Err.Description
End Sub
On Error GoTo Err_cmdSave_Click
If Not (SPC.Checked And SPS.Checked And CheckFree.Checked And SCS.Checked And SIM.Checked) Then
'if its all null then just exit out of the function to give them another shot!
MsgBox "You must select a Product Type", vbOKOnly, "Error"
DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
Else
'success
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.Close
Exit Sub
End If
Err_cmdSave_Click:
MsgBox Err.Description
End Sub
glad to be of assistance
AW
AW
try this
Private Sub cmdSave_Click()
On Error GoTo Err_cmdSave_Click
If IsNull(Me.SPC) And IsNull(Me.SPS) And IsNull(Me.CheckFree) And IsNull(SCS) And IsNull(SIM) Then
'if its all null then just exit out of the function to give them another shot!
MsgBox "You must select a Product Type", vbOKOnly, "Error"
Exit Sub
Else
'success
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.Close
Exit Sub
End If
Err_cmdSave_Click:
MsgBox Err.Description
End Sub
~b