Stack Exchange
Microsoft Access Report.Page uses data from next record
I have a problem with Access when a try to display a barcode on a Access Report. I use the Report.Page event to create the barcode as seen here:
Option Compare Database

Dim barcode As Control

Private Sub Report_Load()
    Set barcode = Me.Tekst15
    Debug.Print ("Geladen report: " + Trim([teldetail_tellijst] & "-" & [teldetail_nummer]))
End Sub

Private Sub Report_page()
    Debug.Print ("Print preview starten voor report: " + Trim([teldetail_tellijst] & "-" & [teldetail_nummer]) + "!")
    Debug.Print ("Loaded report: " + Me.Tekst0)
    Debug.Print ("Barcode to print: " + barcode)
    
    Result = Barcode_128(Me.Tekst15, Me)
    Me.Line (0, 0)-(Me.ScaleWidth, Me.ScaleHeight), , B
End Sub

But it uses the data from the next record.
As seen in this image: report with barcode
if you scan the barcode it will read 10908-2 instead of the expected 10908-1
i tried changing the event where the barcode is generated but then the barcode will not show up. I also tried chaning the size of the record in the print preview to fit the A6 page it is printed on because if i load 2 reports on 1 A4 the barcode will only show up once(still with the data from the next record).
If you need more info to answer the question please let me know so i can provide the info.

Code should be posted into question as formatted text, not an image. Same for sample data. Might want to post in a forum that allows attaching files and provide your db for analysis.

I have a sample db that generates barcodes 128 and 39. Function to include in report is called from Print event of detail section. Did you try that event? Or even Format event?

@june7 when i use the print event the barcode does not display at all

Interesting, my code also has a line that sets boolean variable Result and makes me wonder if you have the same db. Calling from Print event definitely displays barcode. However, I don't have a reader to confirm the barcode correctly represents data.

Loaded a barcode reader on my phone and barcode translates to correct data. My code also does not have barcode public variable. Here's my source https://www.accessforums.net/showthread.php?t=33878

This belongs in the section's Format event. You need to open Print Preview, not Report View, to make this event run.

@Andre, image shows report in PrintPreview and OP says barcode will not show if code is used by Print event. Works for me with either Print or Format.
