Thank you so much for your reply and help. The following is the code I have for printing the for right now:
Private Sub Print_Recruitment_Report_Click()
On Error GoTo Err_Print_Recruitment_Report_Click
Dim stDocName As String
'MsgBox "value=" + RequestNumberTextField
stDocName = "Recruitment 52"
DoCmd.OpenReport stDocName, acNormal
Exit_Print_Recruitment_Report_Click:
Exit Sub
Err_Print_Recruitment_Report_Click:
MsgBox Err.Description
Resume Exit_Print_Recruitment_Report_Click
End Sub
Would I put this statement If checkComplete = True Then in front of my code?
I don't know quite how to put them together?
Thanks for any more help.
Laura
Hi Laura
You could write a function called CheckComplete that validated each of your mandatory fields and if any failed would give an error message to inform the user and prevent printing.
-
-
Private Function checkComplete() As Boolean
-
checkComplete = True
-
If IsNull(Me.txtField1) Or Len(Me.txtField1) < 2 Then
-
checkComplete = False
-
MsgBox "Field " & Me.txtField1.Name & " is incomplete", vbCritical, "Missing Data"
-
Exit Function
-
End If
-
-
If IsNull(Me.txtField2) Or Len(Me.txtField2) < 20 Then
-
checkComplete = False
-
MsgBox "Field " & Me.txtField2.Name & " is incomplete", vbCritical, "Missing Data"
-
Exit Function
-
End If
-
-
End Function
-
The above code first test that the field is not empty and then tests that the user has not entered a prefunctory value to 'cheat' the system. You can set the length to whatever suits you. You must have both checks because an empty field is Null not zero, so doesn't fail the Len() test.
You would call this function from your print button
- If checkComplete = True Then
-
DoCmd.OpenReport "ReportName".....
-
Else
-
Exit Sub
-
End If
-
S7