OK - so all of the validations work except the Report Week validation.
If the HMO = HN etc, and the Report Week is null, then the code works perfectly.
The focus is set to the report week field and I can enter the report week.
Then if I click the add record again, the msgbox pops up again and sayd report week must be filled in etc.
Seems like it is a loop, but I do not know how to fix it.
Code: Select all
Private Sub cmdAddNewRecord_Click()
If Me.Dirty Then
If MsgBox("Do you want to save the changes you have made to the record?", _
vbQuestion + vbYesNo, "CONTINUE?") = vbYes Then
'VALIDATE DATE WORKED
If IsNull(Me.txtDATE_WORKED) Then
MsgBox "YOU MUST FILL IN DATE WORKED.", vbExclamation, "DATA ENTRY ERROR"
Me.txtDATE_WORKED.SetFocus
Exit Sub
End If
'VALIDATE REP
If IsNull(Me.cboREP) Then
MsgBox "YOU MUST FILL IN REP NAME.", vbExclamation, "DATA ENTRY ERROR"
Me.cboREP.SetFocus
Exit Sub
End If
'VALIDATE REPORT NAME
If IsNull(Me.cboREPORT_NAME) Then
MsgBox "YOU MUST FILL IN REPORT NAME.", vbExclamation, "DATA ENTRY ERROR"
Me.cboREPORT_NAME.SetFocus
Exit Sub
End If
'VALIDATE CLIENT
If IsNull(Me.cboCLIENT) Then
MsgBox "YOU MUST FILL IN CLIENT.", vbExclamation, "DATA ENTRY ERROR"
Me.cboCLIENT.SetFocus
Exit Sub
End If
'VALIDATE REPORT MONTH
If IsNull(Me.cboREPORT_MONTH) Then
MsgBox "YOU MUST FILL IN REPORT MONTH.", vbExclamation, "DATA ENTRY ERROR"
Me.cboREPORT_MONTH.SetFocus
Exit Sub
End If
'VALIDATE REPORT WEEK
If cboHMO.Column(0) = "HN" Or cboHMO.Column(0) = "UHW" Or cboHMO.Column(0) = "UHW-ALLIANCE" Or cboHMO.Column(0) = "UHCMS" Or _
cboHMO.Column(0) = "C1ST" Or cboHMO.Column(0) = "SCFHP " And IsNull(Me.cboREPORT_WEEK) Then
MsgBox "YOU MUST FILL IN REPORT WEEK.", vbExclamation, "DATA ENTRY ERROR"
Me.cboREPORT_WEEK.SetFocus
Exit Sub
End If
If Me.txtTOTAL_TRANSACTIONS2 <> Me.txtTOTAL_TRANSACTIONS Then
Me.txtTOTAL_TRANSACTIONS.SetFocus
MsgBox "TRANSACTION TOTAL IS INCORRECT - PLEASE CHECK YOUR TRANSACTION COUNTS", vbCritical, "DATA ENTRY ERROR"
Exit Sub
End If
End If
Else
Me.Undo
End If
DoCmd.GoToRecord , , acNewRec
Exit_cmdAddNewRecord_Click:
Exit Sub
Err_cmdAddNewRecord_Click:
MsgBox Err.Description
Resume Exit_cmdAddNewRecord_Click
End Sub