Why is this happening?

VorLag

Board Regular
Joined
May 13, 2013
Messages
205
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:

8

8


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
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
why do you have OPENREPORT in there twice?
DoCmd.OpenReport "Report1", acViewPreview, , "ID" = lastID
SHOULD WORK,
but not the other.
 
Upvote 0
why do you have OPENREPORT in there twice?
DoCmd.OpenReport "Report1", acViewPreview, , "ID" = lastID
SHOULD WORK,
but not the other.

I have it in there twice because one was opening the report view and the other was opening the preview. I was trying to figure out what was causing one to show up fine and the other to show up incorrectly. When I delete the report view and have just the one line, this happens:

8


Instead of actually opening up the last record, it's displaying a blank record now. When I hover over acViewPreview, it's still showing that its value is 2. When I hover over lastID, the value is 5, which is correct.

8


I don't understand why it's doing this.
 
Upvote 0

Forum statistics

Threads
1,215,331
Messages
6,124,312
Members
449,152
Latest member
PressEscape

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top