Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to populate Dynamic Reports?

Status
Not open for further replies.

Handle5892

Programmer
Mar 5, 2004
3
US
I created several reports dynamically (based on results from several queries). However, I cant get this reports to populate with the data that I want when I preview them.

I set the RecordSource of each report a a particular query stored in the database. In order to get the report to populate I have to add the code below to the Detail_Format Sub. However, I cannot hardcode this becuase the report is generated dynamically. How can I do the below code without using the Detail_Format sub (instead I want to use a fuction defined in one of my modules)?

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

' Put values in text boxes (report controls)
Dim intX As Integer
' Verify that you are not at end of recordset.
'rstCurrViewData is the record set that contains the data
If Not rstCurrViewData.EOF Then
If Me.FormatCount = 1 Then
For intX = 1 To rstCurrViewData.Fields.Count
Me(intX - 1) = rstCurrViewData(intX - 1)
Next intX

' Move to next record in recordset.
rstCurrViewData.MoveNext
End If
End If

End Sub
 
this might not be the exact answer you wanted:
QueryDef: If you aren't aware of this possibility you might want to consider it.

Lookup querydef, it allows you to rewrite a query in code. If you do this right before you open a report, you can change the record source for a report. just use the same fieldnames for each query.

Microsoft Example:
Dim dbsCurrent As Database
Dim qryTest As QueryDef

Set dbsCurrent = CurrentDb
Set qryTest = dbsCurrent.QueryDefs("Employee List")
qryTest.SQL = "SELECT * FROM Employees;"


Mark P.

Bleh
 
Thanks for your reply... that is exactly how I created the queries for the reports... It turns out I can set the RecordSource for each individual text box when I create it (not only when the report was opened as I was trying to do) so this solve the problem.....

this is what happens when you accept a project coding VB when you only know C++... thanks....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top