Preview Button VBA Error

KerryDee

Registered User.
Local time
Today, 11:21
Joined
Nov 24, 2016
Messages
36
Hi hoping for some help on a button I am getting errors on. I want to preview my form in Access but I am getting a "Syntax error (missing operator in query expression id=".
Here is the code I am using: Any help will be greatly appreciated. Thanks very much:

Private Sub btnPreviewDocument_Click()
'This is to preview a single report
Me.Refresh
DoCmd.OpenReport "rptMyReport", acViewPreview, , "id=" & Me!ID
Dim strReport As String
strReport = "rptMyReport"
Me.Refresh
DoCmd.OpenReport strReport, acViewPreview, , "ID=" & Me!ID
Reports(strReport).Visible = True
End Sub
 
It is usually me.ID, not me!ID

also, the ID needs to be populated - assuming ID is an autonumber then if this is a new record, it won't be
 
Thank you very much. You are correct!!! By chance do you know how to tweak the code so that I can preview the current form information (for a single record)?

Thank you very much.
 
not sure what you mean by preview the current form information (for a single record)
 
Sorry, I mean if it this is a new record to preview a single record before printing.

Thank,

KerryDee
 
sorry - still don't understand - may be terminology. A new record is one that hasn't been saved, so you can't run a report on it because there is nothing to run.

Once it has been saved, you can run report. So perhaps on the code behind the report button you need to put

If Me.Dirty Then Me.Dirty = False
DoCmd.OpenReport strReport, acViewPreview, , "ID=" & Me.ID
 

Users who are viewing this thread

Back
Top Bottom