I would put the following into the print button code:
Me.Dirty = False
This attempts to save the record. Then, in the form's Before Update event:
Private Sub Form_BeforeUpdate (Cancel as Integer)
Dim strTitle as String
strTitle = "Incomplete Data"
If Nz(Me.[InspectionBy],"") = "" Then
MsgBox "Please enter Inspection By data", vbInformation, strTitle
Cancel = True
Me.[txtInspectionBy].SetFocus
ElseIf Nz(Me.[Channel],"") = "" Then
MsgBox "Please enter Channel", vbInformation, strTitle
Cancel = True
Me.txtChannel.SetFocus
ElseIf Nz(Me.[Station],"") = "" Then
MsgBox "Please enter Station", vbInformation, strTitle
Cancel = True
Me.txtStation.SetFocus
End If
Station is the field, and txtStation is the text box bound to Station (to use
one example). Use your actual names, of course.
Here is a generic routine that Albert Kallal provided. It is well worth
taking a few minutes to figure it out. Just use your control names and error
messages. For instance, if txtInspectionBy is bound to the InspectionBy
field, the first entry in the list below would be:
colFields.Add "txtInspectionBy|Inspection By"
Albert had used a comma instead of the pipe character (|) in the above and in
the Split functions, but I used the pipe character so I can have a comma in
the validation text if I want. Albert's code and explanation follow.
*******************
I use the following "general" code routine to give custom messages for fields
that are not filled out.
The code below is a great way to verify fields that you want to be requited.
Another nice feature is that after the given message, the cursor (focus)
moves to the field in question.
The code is used as follows:
In the forms before update event..you go:
Cancel = MyVerify.
And, then the two following routines need be put into the form's module. You
can see how in the first example, you just put in the list of controls that
you want requited, and also the text "error" message to display. Note
carefully how the full string is enclosed in quotes.
This routine is called in the forms Load event:
Private Function MyVerify() As Boolean
Dim colFields As New Collection
MyVerify = False
colFields.Add "TourDate|Tour date"
colFields.Add "Description|Description"
colFields.Add "City|City"
colFields.Add "cboProvince|Province"
colFields.Add "StartDate|Start date"
colFields.Add "EndDate|end date"
MyVerify = vfields(colFields)
End Function
Private Function vfields(colFields As Collection) As Boolean
Dim strErrorText As String
Dim strControl As String
Dim i As Integer
vfields = False
For i = 1 To colFields.Count
strControl = Split(colFields(i), "|")(0)
strErrorText = Split(colFields(i), "|")(1)
If IsNull(Me(strControl)) = True Then
MsgBox strErrorText & " is required", vbExclamation, "Required
Field"
Me(strControl).SetFocus
vfields = True
Exit Function
End If
Next i
End Function
--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
What if there is more that one field they have missed?
these are the usual fields they miss: [Inspection By] [Channel] [Station]
thanks jo
Ideally the button should be disabled until all the relevant fields have data
in them but to answer your question
[quoted text clipped - 12 lines]