Using a report multiple times

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • nhienvo@gmail.com

    Using a report multiple times

    I have table of customer information. For each record in the
    table, I'd like to output it to Snapshot passing in a report
    as the type. I'd like to use the same report for every customer.
    The problem I'm having in my VB code is that when I loop through
    the records and output the report to Snapshot, the information
    in the report remains to be the first record. When outputting
    the report, it doesn't move to the next record.

    I'm new to Access, and I'm not sure as to what I need
    for the report to recognize the current record. I've looked in
    the newsgroup, but have tried everything from refreshing
    to requery, opening the report, closing it. I don't
    think I know where I need to put it, or fully
    understand how reports work. My VB code
    does get input from user. Can any one help?

    Here is a sample pseudocode:

    Set db = Currendb()
    Set rs = db.OpenRecordse t ()

    While not rs.EOF
    DoCmd.Outputto acReport,report name,acFormatSN P,dir,false
    rs.Movenext

    End

    Thank you,
    Nhien

  • pietlinden@hotmail.com

    #2
    Re: Using a report multiple times

    Nhien,
    you never filter the report!!! Granted, this is probably ugly, but it
    should work.

    Public Sub OutputReportsTo RTF()

    Set rs = DBEngine(0)(0). QueryDefs("qryC ustomer_A").Ope nRecordset

    While Not rs.EOF
    DoCmd.OpenRepor t "Invoice", acViewPreview, , "[CustomerID]=" &
    rs.Fields("Cust omerID")
    DoCmd.OutputTo acReport, "Invoice", acFormatSNP, "rpt" &
    rs.Fields("Cust omerID") & ".snp", False
    DoCmd.Close acReport, "Invoice", acSaveNo
    rs.MoveNext
    Wend

    rs.Close
    Set rs = Nothing

    End Sub

    Comment

    • pietlinden@hotmail.com

      #3
      Re: Using a report multiple times

      Nhien,
      you never filter the report!!! Granted, this is probably ugly, but it
      should work.

      Public Sub OutputReportsTo RTF()
      'this is my query that retrieves the CustomerID's that I want to create
      invoices for...
      Set rs = DBEngine(0)(0). QueryDefs("qryC ustomer_A").Ope nRecordset

      'passing the individual customerID's to the OpenReport command so 'I
      get a single report per customer. (not one with multiple customers)
      While Not rs.EOF
      DoCmd.OpenRepor t "Invoice", acViewPreview, , "[CustomerID]=" &
      rs.Fields("Cust omerID")

      '--output said report
      DoCmd.OutputTo acReport, "Invoice", acFormatSNP, "rpt" &
      rs.Fields("Cust omerID") & ".snp", False
      DoCmd.Close acReport, "Invoice", acSaveNo
      rs.MoveNext
      Wend

      rs.Close
      Set rs = Nothing

      End Sub

      Comment

      • nhienvo@gmail.com

        #4
        Re: Using a report multiple times

        Thank you all for your help. The suggestions
        worked and I will remember to filter a
        report next time.

        -Nhien

        Comment

        Working...