Dual-criteria required before saving

Baldrick

Registered User.
Local time
Yesterday, 21:36
Joined
Jul 2, 2001
Messages
35
I have the following in the OnClick Event of a "Save" button:

Private Sub cmd69_Click()
On Error GoTo Err_cmd69_Click
Dim currctl As Integer, numctls As Integer
Dim ctl As Control
numctls = Forms!frmAddProject.Count 'counts the number of controls

For currctl = 0 To numctls - 1
Set ctl = Me(currctl)

If Me!cboAddStatus = "C" Then
MsgBox "A Formal Presentation Completion date is required for Completed Projects", vbOKOnly
Me!Form_Pres_Comp.BackColor = 65535
Me!Form_Pres_Comp.SetFocus
End If
Exit Sub

If ctl.Tag = "validate" Then
If IsNull(ctl) Then
MsgBox "You have not filled in information that is required for this project. Please fill in the fields highlighted in YELLOW.", 48, "Field Empty"
ctl.BackColor = 65535
ctl.SetFocus
Exit Sub
End If
End If
Next currctl

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.Close
Exit_cmd69_Click:
Exit Sub

I am trying to first, require a date be entered in a field if a combobox value is "Complete" and second, require additional dropdowns be selected before saving the record.

My code has me stuck in a loop on the first IF statement. What am I missing?
 
I think I've answered my own question...

Private Sub cmd69_Click()
On Error GoTo Err_cmd69_Click

If Me!cboAddStatus = "C" Then
If IsNull(Form_Pres_Comp) Then
MsgBox "A Formal Presentation Completion date is required for Completed Projects", vbOKOnly
Me!Form_Pres_Comp.BackColor = 65535
Me!Form_Pres_Comp.SetFocus
Exit Sub
End If
End If

Dim currctl As Integer, numctls As Integer
Dim ctl As Control
numctls = Forms!frmAddProject.Count 'counts the number of controls

For currctl = 0 To numctls - 1
Set ctl = Me(currctl)

If ctl.Tag = "validate" Then
If IsNull(ctl) Then
MsgBox "You have not filled in information that is required for this project. Please fill in the fields highlighted in YELLOW.", 48, "Field Empty"
ctl.BackColor = 65535
ctl.SetFocus
Exit Sub
End If
End If
Next currctl

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.Close
Exit_cmd69_Click:
Exit Sub

Err_cmd69_Click:
MsgBox Err.Description
Resume Exit_cmd69_Click

End Sub

Works so far.
 

Users who are viewing this thread

Back
Top Bottom