Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print Last Record Only? 1

Status
Not open for further replies.

Donamese

Technical User
Jan 16, 2003
12
US
I am working with a form that has a button to print a record. It prints every record in the master table when clicked, but I only want it to print the last record. I am not sure how to code it....currently it is set as

Private Sub Command42_Click()
On Error GoTo Err_Command42_Click

Dim stDocName As String

stDocName = "Report1"
DoCmd.OpenReport stDocName, acNormal

Exit_Command42_Click:
Exit Sub

Err_Command42_Click:
MsgBox Err.Description
Resume Exit_Command42_Click

End Sub


I know there should be a where clause after the DoCmd but can't find anything to select last record.
 
Hi. What constitutes "last"? Is there an ID field, or a date/time stamp?

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244. Basics at
 
You can use DMAX to find the max ID of the table or query which is your recordsource, then open the report for only that ID:

Code:
dim intMaxID as Integer
intMaxID = DMax("ID","TableOrQueryNameHere")


DoCmd.OpenReport stDocName, acNormal, , "ID = " & intMaxID



Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244. Basics at
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top