open a report from a form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Good morning All,
I have a form with a command button to open a report ( based on a query )
for the currently displayed record. The report has a subform in it where the
"Child" = UnitSN, and the "Master"= TLAUnit. 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
 
From the code that was posted, I noticed a minor error that could certainly
cause the syntax error.
DoCmd.OpenReport stDocName, acPreview, , "TLAUnit = " & Me.UnitSN & "'"

Adding a single quote (') before the Me.UnitSN should fix your issue.

DoCmd.OpenReport stDocName, acPreview, , "TLAUnit = '" & Me.UnitSN & "'"
(Note the SQ added in the DQ surrounding TLAUNIT = '
 
Good morning All,
I have a form with a command button to open a report ( based on a query )
for the currently displayed record. The report has a subform in it where the
"Child" = UnitSN, and the "Master"= TLAUnit. 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

At the very least you are missing a single quote (').
The correct syntax of the where clause will depend upon the datatype
of the [TLAUnit] field.
If it is a Text datatype:
"TLAUnit = '" & Me.UnitSN & "'"
for clarity the above quotes are:
"TLAUnit = ' " & Me.UnitSN & " ' "

If it is a Number datatype, use:
"TLAUnit = " & Me.UnitSN
 
Back
Top