:banghead:
I am afraid I am a bit rusty with VB. Can anyone help me firgure out why this is not working? It may be something simple but I can't see it. This is a form Named LogForm. When the "Save Button" is clicked I want it to check the Packaging Name field (which is a Drop Down Combo Box where a name is selected from a list) to be sure it is not empty. If it is empty I want the focus to shift to that field and highlight the label red. Right now Access bypasses the first section entirely and goes then "If not Cancel" section. It processes all of the code in that section perfectly. Thank you.
Private Sub SaveNewRecord_Click()
On Error GoTo err_handler
Cancel = False
' Check to see if the there is a name in the "Packaging Name" Field
If IsEmpty(Combo113) Then
If MsgBox("You must select a Packaging Name.", vbCritical, "Data Missing...") Then
Me.Combo113.SetFocus
Me.PackagingName_Label = vbRed
Cancel = True
End If
End If
If Not Cancel Then
If MsgBox("Have you checked all fields for accuracy? Do you want to make corrections?", vbYesNo, "Check accuracy before saving...") = vbYes Then
Me.Undo
' If all information is verified. Go to a new record.
Else
If MsgBox("Are you sure you want to save?", vbYesNo, "Save Record.") = vbYes Then
DoCmd.GoToRecord acDataForm, "Container Closure Use and Return Log", acNewRec
End If
End If
End If
cmdSaveNewRecord_exit:
Exit Sub
err_handler:
If Err.Number <> 2105 Then
MsgBox Err.Description, vbExclamation, "Error #: " & Err.Number
End If
Resume cmdSaveNewRecord_exit
End Sub
I am afraid I am a bit rusty with VB. Can anyone help me firgure out why this is not working? It may be something simple but I can't see it. This is a form Named LogForm. When the "Save Button" is clicked I want it to check the Packaging Name field (which is a Drop Down Combo Box where a name is selected from a list) to be sure it is not empty. If it is empty I want the focus to shift to that field and highlight the label red. Right now Access bypasses the first section entirely and goes then "If not Cancel" section. It processes all of the code in that section perfectly. Thank you.
Private Sub SaveNewRecord_Click()
On Error GoTo err_handler
Cancel = False
' Check to see if the there is a name in the "Packaging Name" Field
If IsEmpty(Combo113) Then
If MsgBox("You must select a Packaging Name.", vbCritical, "Data Missing...") Then
Me.Combo113.SetFocus
Me.PackagingName_Label = vbRed
Cancel = True
End If
End If
If Not Cancel Then
If MsgBox("Have you checked all fields for accuracy? Do you want to make corrections?", vbYesNo, "Check accuracy before saving...") = vbYes Then
Me.Undo
' If all information is verified. Go to a new record.
Else
If MsgBox("Are you sure you want to save?", vbYesNo, "Save Record.") = vbYes Then
DoCmd.GoToRecord acDataForm, "Container Closure Use and Return Log", acNewRec
End If
End If
End If
cmdSaveNewRecord_exit:
Exit Sub
err_handler:
If Err.Number <> 2105 Then
MsgBox Err.Description, vbExclamation, "Error #: " & Err.Number
End If
Resume cmdSaveNewRecord_exit
End Sub