Filter Loop with OpenReport

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • epifinygirl
    New Member
    • Aug 2010
    • 19

    Filter Loop with OpenReport

    With my code below, I am trying to filter the 1 report for each record set in the "Temp Table". The report is filtered from a query "Carrier Report".
    Code:
    Public Function OrgIDReports()
    
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim sqlStr As String
    
    sqlStr = "SELECT * FROM [Temp Table]"
    
    Set db = CurrentDb
    Set rs = db.OpenRecordset(sqlStr)
    
    rs.MoveFirst
    
    Do While Not rs.EOF
      DoCmd.OpenReport "I# Report", acViewNormal, , "[Carrier Report].[I#]= & rs"
      rs.MoveNext
    Loop
    
    MsgBox ("End of Client Org IDs")
    
    End Function
    I am currently receiving a "Run time 3075 - Syntax Error (missing operator) in query expression '([Carrier Report].[I#]=&rs)'. With the below line:
    Code:
    DoCmd.OpenReport "I# Report", acViewNormal, , "[Carrier Report].[I#]= & rs"
    Any ideas what I am doing wrong???
  • Marc Brown
    New Member
    • Jul 2010
    • 16

    #2
    I would guess it's how you are sending over the variable rs. Try taking it out of the quotations so it would look like this.

    Code:
      DoCmd.OpenReport "I# Report", acViewNormal, , "[Carrier Report].[I#]=" & chr(34) & rs & chr(34)

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32662

      #3
      Marc's on the right lines but the code's a bit more broken than just that it seems. You also need to provide some value from your rs recordset and it needs to be surrounded by the relevant characters for the type of data. A reference of rs on its own simply points to a recordset object which is unusable. One of the properties must be specified.
      Last edited by NeoPa; Oct 11 '11, 05:42 PM.

      Comment

      • epifinygirl
        New Member
        • Aug 2010
        • 19

        #4
        When I enter your code, I am now getting a "Type Mismatch" error

        Comment

        • epifinygirl
          New Member
          • Aug 2010
          • 19

          #5
          Neopa - I'm not quite sure I follow. Can you post an example?

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32662

            #6
            @EpiphanyGirl
            Code:
            Call DoCmd.OpenReport("I# Report", acViewNormal, , "[I#]=" & rs.?)
            What type of data is [I#]?
            Which field within [Temp Table] are you trying to match it with?

            Comment

            • epifinygirl
              New Member
              • Aug 2010
              • 19

              #7
              I# is a number and the column in [Temp Table] is called I# as well.

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32662

                #8
                Originally posted by EpiphanyGirl
                EpiphanyGirl:
                NeoPa - I'm not quite sure I follow. Can you post an example?
                Your subsequent post (#4) illustrates exactly what I was saying.

                If you answer the questions in my post #6 I can illustrate the point. I don't yet have enough information from you to do so.

                PS. Clearly we are cross-posting ATM, so be patient. I'm sure we'll get it resolved shortly.

                Comment

                • NeoPa
                  Recognized Expert Moderator MVP
                  • Oct 2006
                  • 32662

                  #9
                  In that case :
                  Code:
                  Call DoCmd.OpenReport("I# Report", acViewNormal, , "[I#]=" & rs![I#])

                  Comment

                  • epifinygirl
                    New Member
                    • Aug 2010
                    • 19

                    #10
                    Perfect!! Thanks so much!!

                    One last question - When the OpenReport happens, I have the settings set-up so that it automatically prints the report to PDF (using Scansoft), however, since it's filtered from the same report, everything is saved with the same file name (ie - the report name). Would you know of a way to alter this so that it would also include the I# field that is it filtering on?

                    Comment

                    • NeoPa
                      Recognized Expert Moderator MVP
                      • Oct 2006
                      • 32662

                      #11
                      That may be a problem. I understand that the name of the file is directly linked to the name of the report. Unless you were to create a copy of the report for every time you ran it, possible as a standard database but not when rolled out as an MDE or ACCDE, this would not be possible.

                      If you're interested in exploring that further, post a question on it and I'll go into more detail. I can't do so here as it's a thread for a different question.

                      Comment

                      Working...