|
Question : Creating a report w/VBA
|
|
Hello all,
Have what I hope is an easy question. I have created a report, and on that report have several fields, looks like this:
Report Header---------------------- Daily Customer Detail Report - 12/13/2004
Report Detail-------------------------
Customer Name: [customer name field] Customer ID: [customer id field] Customer Address: [customer address field 1] [customer address field 2] [customer city field], [customer state field] [customer zipcode field] etc.
And on and on down the page. I am displaying a lot of customer info on the report. Now, I know that I can assign a record source to a report (query), and then build the report using the fields in the underlying query. However, I do not want to go this way. Instead, I want to use VBA in the Activate event to build my report. I know how to code the query and populate the report fields, that's fairly easy. What I don't know how to do is to force my report to display all of my customer records.
For instance, the following query will return 5 records:
Set customerRS = customerDB.OpenRecordset("SELECT * FROM Customers WHERE Entered_Date = #12/13/2004#")
Now, I'd like to display the records in my report (I should have one detail page for each record):
Do Until customerRS.EOF 'Assign Field values here customerRS.MoveNext Loop
I know that the recordset contains five records, but my report only ever displays the last record in the recordset. In other words, where I'd expect to have five pages in my report (one for each record), I have only 1. What I think is I am missing something that tells the report to, essentially, create a new page report for each record, as is done if I assign the query as the report's record source. What am I missing here?
OK, hopefully this is clear, if not, just let me know and I will either clarify or provide more info. I am assigning this question a value of 500 points because it is important I get an answer as quickly as possible.
Thank You,
Arek
|
|
Answer : Creating a report w/VBA
|
|
Hi Arek
Use the easy approach. Use a query (or temp table) to define the data behind the report. If you want to control the report from a VBA looping through a recordset, then just put the fields you want into a temp table and then send this to a normal report. IMHO, you cannot get the level of control you want on a report from VBA. I'd be interested if you can show that it is possible though!
Cheers
|
|
|
|