Error 3021 No current record

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
 
A

Allen Browne

Instead of:
If Me.Field137 = "" Then
try:
If IsNull(Me.Field137) Then

A Null is not the same as a zero-length string.
 
D

dbl

Allen than brings up the message but as soon as you click the ok button it
still goes into the Error 3021 message. How do I stop that.

Thanks for your help.

Bob

Allen Browne said:
Instead of:
If Me.Field137 = "" Then
try:
If IsNull(Me.Field137) Then

A Null is not the same as a zero-length string.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

dbl said:
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
 
A

Allen Browne

Comment out the error handler, by adding a single quote to the start of line
2, i.e.:
'On Error GoTo Err_Button258_Click
Then see which line produces the error.

I don't really understand your code, e.g. what LinkCriteria is doing. If you
don't want the report to be opened if the data is not satisfactory, you
might use an Else in the If block.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

dbl said:
Allen than brings up the message but as soon as you click the ok button it
still goes into the Error 3021 message. How do I stop that.

Thanks for your help.

Bob

Allen Browne said:
Instead of:
If Me.Field137 = "" Then
try:
If IsNull(Me.Field137) Then

A Null is not the same as a zero-length string.


dbl said:
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.
 
D

dbl

Allen it still goes to the line varYrs = DateDiff("yyyy", varTestDate,
Date) in the function code. Not in the Command button code.

The LinkCriteria is making sure that the reports that are printed are in
the current record, the data that is missing goes on to the reports. I.e.
record CustomerID 213800 is the one we what to print.
Allen Browne said:
Comment out the error handler, by adding a single quote to the start of
line 2, i.e.:
'On Error GoTo Err_Button258_Click
Then see which line produces the error.

I don't really understand your code, e.g. what Cis doing. If you don't
want the report to be opened if the data is not satisfactory, you might
use an Else in the If block.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

dbl said:
Allen than brings up the message but as soon as you click the ok button
it still goes into the Error 3021 message. How do I stop that.

Thanks for your help.

Bob

Allen Browne said:
Instead of:
If Me.Field137 = "" Then
try:
If IsNull(Me.Field137) Then

A Null is not the same as a zero-length string.


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.
 
D

dbl

The "Else" sorted it out.

Thanks very much for your help.
Bob
Allen Browne said:
Comment out the error handler, by adding a single quote to the start of
line 2, i.e.:
'On Error GoTo Err_Button258_Click
Then see which line produces the error.

I don't really understand your code, e.g. what LinkCriteria is doing. If
you don't want the report to be opened if the data is not satisfactory,
you might use an Else in the If block.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

dbl said:
Allen than brings up the message but as soon as you click the ok button
it still goes into the Error 3021 message. How do I stop that.

Thanks for your help.

Bob

Allen Browne said:
Instead of:
If Me.Field137 = "" Then
try:
If IsNull(Me.Field137) Then

A Null is not the same as a zero-length string.


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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top