run-time error 3075

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

Guest

I have the following message when clicking on a command button designed to
print a report based on the current record in a tabbed form.

Syntax error (missing operator) in query expression '(MachNumber=2G-CH01)'.

The following code is on the "click" event of the button:

Private Sub MachTag_Click()
DoCmd.OpenReport "M-Equipment Tag", acPreview, , "MachNumber = " &
Me!MachNumber
End Sub

The 1st tab of the form is pulling the MachNumber data directly from the
table. The 2nd tab form (is a subform) and is pulling the data from a second
table.

I do not have any query associated with either form.

When I remove the ", , "MachNumber = " & Me!MachNumber" from the code I am
able to preview the entire report, but want I want to do is print the report
for the current record shown on the 1st tab form.

Thank You,
 
Given your example, MachNumber must be a Text field (not a Number field.)
Therefore it needs extra quotes:

Dim strWhere As String
strWhere = "MachNumber = """ & Me!MachNumber & """"
DoCmd.OpenReport "M-Equipment Tag", acPreview, , strWhere

If the quotes don't make sense, see:
Quotation marks within quotes
at:
http://allenbrowne.com/casu-17.html
 
MachNumber is a text field, so you need to delimit the text value with
single-quote marks. Try:
DoCmd.OpenReport "M-Equipment Tag", acPreview, , "MachNumber = '" &
Me!MachNumber & "'"

HTH,

Rob
 
That was it - Thank You

Rob Parker said:
MachNumber is a text field, so you need to delimit the text value with
single-quote marks. Try:
DoCmd.OpenReport "M-Equipment Tag", acPreview, , "MachNumber = '" &
Me!MachNumber & "'"

HTH,

Rob
 
Back
Top