I am checking for completed fields within a form in the Before Update event. However within the Form Unload event I am also using open args code to close the form and open the previous form. The problem is that when my MsgBox comes up and I check the OK button, the darn form closes!
Can anyone please advise? Thanks in advance
BEFORE UPDATE CODE
Private Sub Form_BeforeUpdate(Cancel As Integer)
'Place an asterisk (*) in the Tag Property of the text
'boxes you wish to validate.
'Then in the BeforeUpdate Event of the form, copy/paste the following:
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
End Sub
FORM UNLOAD CODE
Private Sub Form_Unload(Cancel As Integer)
On Error Resume Next
Forms(Me.OpenArgs).Visible = True
Forms!Project_Edit.cboCompanyID.Requery
End Sub
Can anyone please advise? Thanks in advance
BEFORE UPDATE CODE
Private Sub Form_BeforeUpdate(Cancel As Integer)
'Place an asterisk (*) in the Tag Property of the text
'boxes you wish to validate.
'Then in the BeforeUpdate Event of the form, copy/paste the following:
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
End Sub
FORM UNLOAD CODE
Private Sub Form_Unload(Cancel As Integer)
On Error Resume Next
Forms(Me.OpenArgs).Visible = True
Forms!Project_Edit.cboCompanyID.Requery
End Sub