open report on a form with a button

krberube

just beyond new
Local time
Yesterday, 20:03
Joined
Jan 14, 2005
Messages
142
Good morning All,
I have a form with a command button to open a report ( based on a query ) for the currently displayed record. here is the code I have used:

Private Sub CS_notes_Click()
On Error GoTo Err_CS_notes_Click
Dim stDocName As String

stDocName = "InternalSNwithRMAprodMASData"
DoCmd.OpenReport stDocName, acPreview, , "TLAUnit = " & Me.UnitSN & "'"

Exit_CS_notes_Click:
Exit Sub

Err_CS_notes_Click:
MsgBox Err.Description
Resume Exit_CS_notes_Click

End Sub

I believe this came from this forum sometime. When the button is clicked I receive the error:
"Syntax error (missing operator) in query expression '(TLAUnit = 26712B')'

TLAUnit is the report field, UnitSN is the form field.
Any help with the error?
Thanks
Kevin
 
Try this ....

Dim strDocName As String
Dim strLinkCriteria As String

strDocName = "ReportName"
strLinkCriteria = "[FieldName] = Forms![FormName]![FieldName]"

DoCmd.OpenReport strDocName, acNormal, , strLinkCriteria


hth,
Michael
 
"TLAUnit = " & Me.UnitSN
 
Ukraine82,
I tried your way and it prompts me for the UnitSN ( which is the current record) any way areound the prompt?

Rich,
I also tried yours and still get the same Syntax error. any other ideas

I believe string is correct as the fields contain both letters and numbers (text fields).

Thanks
Kevin
 
I think I know why its asking me for UNITSN, The report ahs a subreport in it.
in the report the Child is "UnitSN" and the Master is "TLAUnit"

can i somehow get the "child" into the code, so it doesn't ask anymore?

Kevin
 
got it fixed! needed to use a report based on a query that did not PROMPT for input. made copies of the existing query and report then removed the prompt from the query and made my form button point to the new coy of the report.
 

Users who are viewing this thread

Back
Top Bottom