Results 1 to 3 of 3
  1. #1
    5 Star Lounger
    Join Date
    Jan 2001
    Posts
    1,119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Print record showing on form (2003)

    I have a form with a print button to print the record on the screen. I am using the following code behind the print button:
    Private Sub cmdPrint_Click()

    On Error GoTo ErrHandler
    DoCmd.OpenReport "rptSummaryforform", acViewPreview, , "Cl Num = " & Me.[CL Num]

    Exit Sub

    ErrHandler:
    If Err = 2501 Then
    'cancelled - ignore
    Else
    MsgBox Err.Description, vbExclamation
    End If
    End Sub

    I am getting a syntax error: Syntax Error(missing operator) in query expression '(cl num = 000052)'.

    Cl num is a text field. The original code that I copied from another database had code -
    DoCmd.OpenReport "Report for Rep Search5", acViewPreview, , "SFId = " & Me.SFID

    SFId is an autonumber field. Would I have to code differently for a text field? There is also a space between Cl and Num but that is the way I get the data.
    Thanks for your help.....

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Print record showing on form (2003)

    Access gets confused because your field name contains a space. Just like at the end of the same line, you should enclose the field name in square brackets. And since it apparently is a text field, you must put quotes around the value:

    ..., "[CL Num] = " & Chr(34) & Me.[CL Num] & Chr(34)

    Chr(34) is the double quote character <code>"</code>

    (This confusion is a good reason not to use spaces in the names of fields, controls, etc. Omit the spaces, or replace them with underscores, e.g. CL_Num)

  3. #3
    5 Star Lounger
    Join Date
    Jan 2001
    Posts
    1,119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Print record showing on form (2003)

    Thanks Hans.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •