Results 1 to 5 of 5
  1. #1
    tagteam is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    486

    Print report for all customers with changed revenue

    I would like to loop through a list of customers that have revenue changed from last month. I have the query that gives me the name of the customers but I am not sure how to create the loop as I am not very good at programming. I think you do a loop through a recordset.



    I was thinking of trying something like this


    Dim rs As DAO.Recordset
    Set rs = CurrentDb.OpenRecordset("q_Invoicing_ATest") 'This is my query
    With rs
    Do While Not .EOF
    DoCmd.OpenReport "BOMI_Report", acViewPreview, , "CustomerId = " & Me.CustomerID - not sure what to do with this part
    .MoveNext
    Loop
    End With
    rs.Close
    Set rs = Nothing

    The problem is I am not sure if that where clause will work since it will just be a query and not coming from a form. I am kind of shooting in the dark here and any help would be appreciated.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    that should work, but you probably don't want to preview each report,
    you can either print to printer:
    DoCmd.OpenReport "BOMI_Report", , , "CustomerId = " Me.CustomerID

    or print the report to a PDF:

    vFile = "c:\temp\Bomi_cust" & Me.CustomerID & ".pdf
    docmd.OutputTo acOutputReport ,"BOMI_Report",acformatPDF, vFile

    (but you need a form for the report query to see the customer id )

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Need to reference recordset field for dynamic parameter, not form field/control.

    DoCmd.OpenReport "BOMI_Report", , , "CustomerId = " & rs!CustomerID
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    tagteam is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    486
    ok, here is what I have so far

    Dim PreviousMonth As Double
    PreviousMonth = Me.PreviousMonth
    Dim CurrentMonth As Double
    CurrentMonth = Me.CurrentMonth
    Dim rs As DAO.Recordset
    Set rs = CurrentDb.OpenRecordset("A_Invoicinv_Print")
    With rs
    Do While Not .EOF

    DoCmd.OpenReport "r_Invoicing_Header_Details", acViewReport, , "CustomerID = " & rs!CustomerIDNumber & " And BillingPeriod=" & PreviousMonth
    DoCmd.OpenReport "r_Invoicing_Header_Details-FirstRunCompare", acViewReport, , "CustomerID = " & rs!CustomerIDNumber & " And BillingPeriod=" & CurrentMonth

    .MoveNext
    Loop
    End With
    rs.Close
    Set rs = Nothing
    End Sub



    Currently I am getting an error - Runtime error 3061 - Too few parameters. Expected 2 . If I manually enter the customerId and billing period in the report it does pull up correctly so somehow it is not getting the correct CustomerID and Billingperiod. When I debug and put my mouse over Previous month it is correct. However, when I put my mouse over rs!CustomerIDNumber i get rs!CustomerIDNumber: <object variable or With block variable not set>

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    What is A_Invoicinv_Print - a query? What fields are retrieved?

    If you want to provide db for analysis, follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Printing report for mutiple customers
    By Freddie81 in forum Reports
    Replies: 17
    Last Post: 09-28-2018, 06:46 PM
  2. Replies: 3
    Last Post: 04-28-2017, 09:51 AM
  3. Replies: 5
    Last Post: 08-06-2015, 03:26 PM
  4. Replies: 1
    Last Post: 02-21-2015, 11:35 PM
  5. Show revenue by month problem
    By TheOmniJuggler in forum Queries
    Replies: 3
    Last Post: 04-15-2011, 10:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums