Blocking Error 3021 No current record

  • Thread starter Thread starter dbl
  • Start date Start date
D

dbl

Hi I have a form with a field called "Field137" if this field is left blank
for any reason when trying to print out certain reports using the following
code:


Private Sub Command258_Click()
On Error GoTo Err_Button258_Click

If Me.Field137 = "" Then
MsgBox "You have not entered Bodyshop To Be Assigned or a Bodyshop Name"
End If
Dim LinkCriteria As String
DoCmd.DoMenuItem A_FORMBAR, A_FILE, A_SAVERECORD, , A_MENU_VER20
LinkCriteria = "[Field143]"

Docname = "ClaimForm"
DoCmd.OpenReport Docname, acPreview
Docname = "ClaimFormLetterFaxRpt"
DoCmd.OpenReport Docname, acPreview

Exit_Button258_Click:
Exit Sub

Err_Button258_Click:
MsgBox Error$
Resume Exit_Button258_Click
Exit Sub
End Sub

If field137 is left blank for any reason then up pops the error box giving
the following message "ERROR 3021 No current record", when you go into debug
it highlights the following function

Function LiscYrs(varTestDate As Variant) As Variant
Dim varYrs As Variant

If IsNull(varTestDate) Then
varYrs = Null
Else
varYrs = DateDiff("yyyy", varTestDate, Date)
(THIS IS THE LINE HIGHLIGHTED IN YELLOW)

If Date < DateSerial(Year(Date), Month(varTestDate), _
Day(varTestDate)) Then
varYrs = varYrs - 1
End If
End If
LiscYrs = varYrs

End Function


How do I get the code to print this error msg MsgBox "You have not entered
Bodyshop To Be Assigned or a Bodyshop Name"
and not jump into any code I would like it to set the focus on Field137 if
possible when the operator clicks the ok button.

Any help would be appreciated.

Bob
 
Back
Top