I am trying to get a report to open into Preview mode with the latest record, but I am having trouble. I can't find anything online that will help me figure out why this issue is happening or how to fix it. When I open the report, it shows whatever the last record is (based on ID). In this case, the last ID is 5. That's fine and that's what I want it to show. However, when I switch to Preview mode, the report shows me ID 2 and I have no idea why. That isn't the last record or the first record. It seems totally arbitrary.
I have my VBA up and I am trying to figure out how to get it to select the last record based on ID. When I hover over acViewReport and acViewPreview, I see that acViewReport (which was fine) is equal to 5 and that acViewPreview (which is not) is equal to 2. I have screenshots here to show what I mean:
I'm not sure where to go from here. I feel like I'm close to resolving this problem, but I don't know what to do to actually fix this. What do I need to do to fix this so that the report preview is showing the last record like the regular report view already is? This is my code thus far:
I have my VBA up and I am trying to figure out how to get it to select the last record based on ID. When I hover over acViewReport and acViewPreview, I see that acViewReport (which was fine) is equal to 5 and that acViewPreview (which is not) is equal to 2. I have screenshots here to show what I mean:
I'm not sure where to go from here. I feel like I'm close to resolving this problem, but I don't know what to do to actually fix this. What do I need to do to fix this so that the report preview is showing the last record like the regular report view already is? This is my code thus far:
Code:
Private Sub Command31_Click()
On Error GoTo Command31_Click_Err
Dim rpt As Report
Dim strReportName As String
strReportName = "Report1"
lastID = DMax("ID", "tblRequests")
DoCmd.OpenReport strReportName, acViewReport
Set rpt = Reports(strReportName)
DoCmd.OpenReport "Report1", acViewPreview, , "ID" = lastID