for the future please use the code tags (the # button) to surround your code to preserve formatting/indentation
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Error_Form_BeforeUpdate
Dim ctlControl As Control
For Each ctlControl In Controls
Select Case ctlControl.ControlType
Case acTextBox, acComboBox
If Len(Nz(ctlControl.Value, "")) = 0 And Len(ctlControl.Tag) > 1 Then
Cancel = True
gsubMessage_MissingData ctlControl.Tag
ctlControl.SetFocus
GoTo Exit_Form_BeforeUpdate
End If
Case acCheckBox
If IsNull(ctlControl.Value) And Len(ctlControl.Tag) > 1 Then
'>>>>>>>>>>>>>>>>>>
' a control with Tag length > 1 (e.g. Tag=Pack for mandatory CheckBox chkPack
'>>>>>>>>>>>>>>>>>>
' this code is not being execued because the CheckBox Value is 0 not Null even though the CheckBox has not been clicked
Cancel = True
gsubMessage_MissingData ctlControl.Tag
ctlControl.SetFocus
GoTo Exit_Form_BeforeUpdate
End If
End Select
Next
If NewRecord Then
txtID = Nz(DMax("lngID", "tblOvernights"), 0) + 1
txtCreatedBy = gintCurrentOperatorID
txtCreated = Now()
End If
txtLastEditedBy = gintCurrentOperatorID
txtLastEdited = Now()
Exit_Form_BeforeUpdate:
Set ctlControl = Nothing
Exit Sub
Error_Form_BeforeUpdate:
gsubMessage_Error Err.Number, Err.Description, Name, "Form_BeforeUpdate"
Resume Exit_Form_BeforeUpdate
End Sub
I am able to replicate the issue, not sure what is causing it, but suggest perhaps a different way
have a public Boolean variable for the form (or perhaps an array if you have many checkboxes
set to false in the form current event
set to true in the control after update event
then use that to determine if a control has been updated or not