Validating field within print single record code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
This code worked for a while, then stopped. I'm trying to be sure the
client completes a "Limitation" field called cboLimits, before printing, and
I have the following code:

If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If

If Me.NewRecord Then 'Check there is a record to print
Msgbox "Select a record to print"
Else
strWhere = "[ID] = " & Me.[ID]
If cboLimits = "" Then
Msgbox "Enter limitations, if any."
Me.cboLimits.SetFocus
Exit Sub
Else
DoCmd.OpenReport strReport, acViewPreview, , strWhere
End If
End If
End Sub

It doesn't seem to be evaluating the cboLimits field, and just prints an
empty space in the field on the report.

Am I missing something?

Thank you,
Karl
 
Hi Ofer,
That worked great. I'll have to read up on what Len means.. Thank you so
much!
Karl

Ofer said:
Just incase the value of the combo is Null and not empty, then try this

If Len("" & Me.cboLimits) = 0 Then
Msgbox "Enter limitations, if any."
Me.cboLimits.SetFocus
Exit Sub
Else
DoCmd.OpenReport strReport, acViewPreview, , strWhere
End If

--
The next line is only relevant to Microsoft''s web-based interface users.
If I answered your question, please mark it as an answer. It''s useful to
know that my answer was helpful
HTH, good luck


Karl H said:
Hi,
This code worked for a while, then stopped. I'm trying to be sure the
client completes a "Limitation" field called cboLimits, before printing, and
I have the following code:

If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If

If Me.NewRecord Then 'Check there is a record to print
Msgbox "Select a record to print"
Else
strWhere = "[ID] = " & Me.[ID]
If cboLimits = "" Then
Msgbox "Enter limitations, if any."
Me.cboLimits.SetFocus
Exit Sub
Else
DoCmd.OpenReport strReport, acViewPreview, , strWhere
End If
End If
End Sub

It doesn't seem to be evaluating the cboLimits field, and just prints an
empty space in the field on the report.

Am I missing something?

Thank you,
Karl
 
Back
Top