Printing current record

A

akrashid

Hi All,

I have a Access 2003 application. Here is my problem.
When I create a new record and then right away I want to print it. I
get an error saying "This record contains no data" even though data is
in the form. If I then scroll the mouse button up or down one record or
more and come back to my current record it prints fine. Some how I am
not picking my current record's autonumber.

Thanks for all your help.

Here is the code, my ID field is a autonumber field:
==================================================
Private Sub Command219_Click()
Dim strReportName As String
Dim strCriteria As String

If NewRecord Then
MsgBox "This record contains no data." _
, vbInformation, "Invalid Action"
Exit Sub
Else
strReportName = "IT_TR_REPORT"
strCriteria = "[ID]=" & Me![ID]


DoCmd.OpenReport strReportName, acViewPreview, , strCriteria

End If
End Sub
==========================================================
 
M

Marshall Barton

I have a Access 2003 application. Here is my problem.
When I create a new record and then right away I want to print it. I
get an error saying "This record contains no data" even though data is
in the form. If I then scroll the mouse button up or down one record or
more and come back to my current record it prints fine. Some how I am
not picking my current record's autonumber.

Thanks for all your help.

Here is the code, my ID field is a autonumber field:
==================================================
Private Sub Command219_Click()
Dim strReportName As String
Dim strCriteria As String

If NewRecord Then
MsgBox "This record contains no data." _
, vbInformation, "Invalid Action"
Exit Sub
Else
strReportName = "IT_TR_REPORT"
strCriteria = "[ID]=" & Me![ID]


DoCmd.OpenReport strReportName, acViewPreview, , strCriteria

End If
End Sub
==========================================================


You are not getting an error message. You are getting the
message your code creates for a new record, so your test
verifies that the code is working properly.

Maybe(?) you want to revise the code so it saves the new or
edited record before trying to print it??

Private Sub Command219_Click()
Dim strReportName As String
Dim strCriteria As String

If Me.Dirty Then Me.Dirty = False
If Me.NewRecord Then
MsgBox "This record contains no data." _
, vbInformation, "Invalid Action"
Exit Sub
End If

strReportName = "IT_TR_REPORT"
strCriteria = "[ID]=" & Me![ID]
DoCmd.OpenReport strReportName, acViewPreview, , _
strCriteria

End Sub
 
A

akrashid

Thank you so much for you help guys, you guys are the greatest.



Marshall said:
I have a Access 2003 application. Here is my problem.
When I create a new record and then right away I want to print it. I
get an error saying "This record contains no data" even though data is
in the form. If I then scroll the mouse button up or down one record or
more and come back to my current record it prints fine. Some how I am
not picking my current record's autonumber.

Thanks for all your help.

Here is the code, my ID field is a autonumber field:
==================================================
Private Sub Command219_Click()
Dim strReportName As String
Dim strCriteria As String

If NewRecord Then
MsgBox "This record contains no data." _
, vbInformation, "Invalid Action"
Exit Sub
Else
strReportName = "IT_TR_REPORT"
strCriteria = "[ID]=" & Me![ID]


DoCmd.OpenReport strReportName, acViewPreview, , strCriteria

End If
End Sub
==========================================================


You are not getting an error message. You are getting the
message your code creates for a new record, so your test
verifies that the code is working properly.

Maybe(?) you want to revise the code so it saves the new or
edited record before trying to print it??

Private Sub Command219_Click()
Dim strReportName As String
Dim strCriteria As String

If Me.Dirty Then Me.Dirty = False
If Me.NewRecord Then
MsgBox "This record contains no data." _
, vbInformation, "Invalid Action"
Exit Sub
End If

strReportName = "IT_TR_REPORT"
strCriteria = "[ID]=" & Me![ID]
DoCmd.OpenReport strReportName, acViewPreview, , _
strCriteria

End Sub
 

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