I use this code in the Before Update event to check if all required fields have been filled out.
Dim msg As String, Style As Integer, Title As String
Dim nl As String, ctl As Control
nl = vbNewLine & vbNewLine
For Each ctl In Me.Controls
If ctl.ControlType = acTextBox Then
If ctl.Tag = "*" And Trim(ctl & "") = "" Then
msg = "Data Required for '" & ctl.Name & "' field!" & nl & _
"You can't save this record until this data is provided!" & nl & _
"Enter the data and try again . . . "
Style = vbCritical + vbOKOnly
Title = "Required Data..."
MsgBox msg, Style, Title
ctl.SetFocus
Cancel = True
Exit For
End If
End If
Next
It works well when I try to navigate to another record.
However when I click a custom button to close the from (docmd.close) it closes without firing the code
in the Before Update event. In other words, the form closes even when a required field is empty.
Obviously I'm overlooking something.
Any suggestions will be appreciated.
Gerrit
Dim msg As String, Style As Integer, Title As String
Dim nl As String, ctl As Control
nl = vbNewLine & vbNewLine
For Each ctl In Me.Controls
If ctl.ControlType = acTextBox Then
If ctl.Tag = "*" And Trim(ctl & "") = "" Then
msg = "Data Required for '" & ctl.Name & "' field!" & nl & _
"You can't save this record until this data is provided!" & nl & _
"Enter the data and try again . . . "
Style = vbCritical + vbOKOnly
Title = "Required Data..."
MsgBox msg, Style, Title
ctl.SetFocus
Cancel = True
Exit For
End If
End If
Next
It works well when I try to navigate to another record.
However when I click a custom button to close the from (docmd.close) it closes without firing the code
in the Before Update event. In other words, the form closes even when a required field is empty.
Obviously I'm overlooking something.
Any suggestions will be appreciated.
Gerrit