Previewing current record in form

sweetcaro

New member
Local time
Today, 00:18
Joined
May 25, 2001
Messages
9
I have a form and added a preview form button that is supposed to open the report using the current information entered in the current form.
The problem I'm having is that when I click on preview report it shows the first record in the table rather than the current record I just created, so i have to click on the next page until I get to the current record.
How do I set the preview report to show the preview of the current record opened in the form?
This is the code for the preview button:
Private Sub Previewreport_Click()
On Error GoTo Err_Previewreport_Click

Dim stDocName As String

stDocName = "Summary"
DoCmd.OpenReport stDocName, acPreview

Exit_Previewreport_Click:
Exit Sub

Err_Previewreport_Click:
MsgBox Err.Description
Resume Exit_Previewreport_Click

End Sub

Should I be saving this record before previewing it?
 
You need to reference the Primary Key Field in the form.
[MyID] in the following example...


Dim stDocName As String

stDocName = "Summary"
DoCmd.OpenReport stDocName, acPreview, ,"[MyID]=[Forms]![MyFormName]![MyID]"

Exit_Previewreport_Click:
Exit Sub

Err_Previewreport_Click:
MsgBox Err.Description
Resume Exit_Previewreport_Click


HTH
 

Users who are viewing this thread

Back
Top Bottom