Print Current Record from Form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • KCwiz
    New Member
    • Jun 2009
    • 6

    Print Current Record from Form

    I am relatively new at this stuff, but I have managed to create two awesome databases for a law office. I am finishing up with a "print report from current record" command button. I have worked my way to this..
    Code:
    DoCmd.OpenReport"File Request", acViewNormal,,"[ID] = "&Me![CLIENT]
    ID is a number. This gets me where I want to be but I get a syntax error "operator missing" @ 'ID=client'. I have tried rearranging and other syntax. I have seen it done a couple of ways, but the above actually gets me to the current client data.

    I need help. I am going crazy.
    Last edited by NeoPa; Jun 9 '09, 09:13 PM. Reason: Please use the [CODE] tags provided.
  • ChipR
    Recognized Expert Top Contributor
    • Jul 2008
    • 1289

    #2
    For debugging, try this.
    Code:
    Dim strWhere as String
    strWhere = "[ID] = " & Me.Client
    MsgBox strWhere   'or breakpoint for Debug
    DoCmd.OpenReport "File Request", acViewNormal, , strWhere

    Comment

    • KCwiz
      New Member
      • Jun 2009
      • 6

      #3
      Try Again

      Didn't work, gave me message box "ID = Jan Smith" Ok? So I clicked ok and it returned the same error message "Syntax Error (missing operator) 'ID = Jan Smith'

      If I try it a different way (I have tried so many) "on click" it asks for ID--Parameter Value

      HELP, this is the last part of my db and I am done.

      Kim

      Comment

      • ChipR
        Recognized Expert Top Contributor
        • Jul 2008
        • 1289

        #4
        Yes, it worked perfectly, but your logic is wrong. I thought you said that ID was a number. Clearly you want something other than [Client] from your form.

        Comment

        • KCwiz
          New Member
          • Jun 2009
          • 6

          #5
          Ok

          The ID is a number "long integer". Here's what I am doing. I want a command button on my form that will print a report of the current record based on a query I created for the report that contains the fields, CLIENT, ADDRESS, REP, TYPE. So after much googling I found
          Code:
          DoCmd.OpenReport "ReportName", acViewNormal,,"[ID] = & Me![ID]
          When I use this one, it returns the "Enter Parameter Value".

          Thank you so much for your quick responses!!!!

          KC
          Last edited by NeoPa; Jun 9 '09, 09:15 PM. Reason: Please use the [CODE] tags provided.

          Comment

          • ChipR
            Recognized Expert Top Contributor
            • Jul 2008
            • 1289

            #6
            So your report does not have the [ID] field? Maybe you need:
            Code:
            Dim strWhere as String 
            strWhere = "[Client] = '" & Me.Client & "'"
            'MsgBox strWhere   'or breakpoint for Debug 
            DoCmd.OpenReport "File Request", acViewNormal, , strWhere

            Comment

            • ChipR
              Recognized Expert Top Contributor
              • Jul 2008
              • 1289

              #7
              Consider any code you find as example only. You will very rarely be able to copy and use code without changing field names such as [ID] to the proper names that you have chosen. In this case, ID should be replaced with the name of the field you use as the primary key, which IDentifies the record.

              Comment

              • KCwiz
                New Member
                • Jun 2009
                • 6

                #8
                Better

                Printed all records now.

                Thanks for your help! What am I missing. It usually doesn't take me this long to "get it".

                KC

                Comment

                • KCwiz
                  New Member
                  • Jun 2009
                  • 6

                  #9
                  Id

                  I realize about the copying code. I use it to point me in the right direction. I do have an ID field (autonumber). That is why I left it in I changed it originally to ....."[ID] = "&Me! [CLIENT]
                  and that got me to where it was actually picking up the current record, but also giving me the syntax error (missing operator).

                  thanks.

                  KC

                  Comment

                  • NeoPa
                    Recognized Expert Moderator MVP
                    • Oct 2006
                    • 32633

                    #10
                    Originally posted by KCwiz
                    Thanks for your help! What am I missing. It usually doesn't take me this long to "get it".
                    It's hard to know Kim.

                    Lookups (where you have a number associated with a string and you use that number to represent the string) are often a source of confusion.

                    Filtering on the [ID] value, generally requires a number. Often these numbers are hidden behind a ComboBox control where only the string value is visible. In such cases the number is generally used by the program, and needs to be passed into the SQL for the filter.

                    Does this make sense?

                    Comment

                    • KCwiz
                      New Member
                      • Jun 2009
                      • 6

                      #11
                      I got it!!!!

                      LET ME THANK YOU GUYS FOR YOUR HELP!!! I came in this a.m. and started playing around with it and this is what worked. I could swear I used this before.
                      Code:
                      Private Sub
                      Dim strWhere As String
                      DoCmd.OpenReport"REPORT", acViewNormal,,"[CLIENT] = ' " & Me.CLIENT & " ' "
                      
                      End Sub
                      AGAIN, thanks for your help!!!!

                      KC
                      Last edited by NeoPa; Jun 10 '09, 01:22 PM. Reason: Please use the [CODE] tags provided.

                      Comment

                      • NeoPa
                        Recognized Expert Moderator MVP
                        • Oct 2006
                        • 32633

                        #12
                        Hi Kim. Welcome to Bytes!

                        Let me just add some clarification here, for other readers benefits.

                        This code is not copy/pasted in and should not be expected to work as is. The spaces around the single-quotes will mean that no real data is ever matched. The actual code used is not exactly as posted here. This is almost certainly due to copying the data inaccurately. It probably works fine in real-life.

                        As a last point, I should mention that the CODE tags must be used when posting. This is not optional. As a new member I'm sure you're just getting to grips with things so I'll include some helpful pointers on this.

                        Tags are done as matching pairs where the opening one is surrounded by [...] and the closing one by [/...]. A set of buttons is available for ease of use in the Standard Editor (Not the Basic Editor). The one for the [ CODE ] tags has a hash (#) on it. You can choose which editor to use in your profile options (Look near the bottom of the page).

                        Very last point, as I'm posting anyway, Line #2 is redundant.

                        Comment

                        Working...