Dynamic Reports

  • Thread starter Thread starter Bryan
  • Start date Start date
B

Bryan

Hello,

I'm trying to create a report with various fields (around
6 each month). The problem is that these 6 fields could be
anything. I have a query which pulls the data fine, but
when I try to dynamically set the control source of a
textbox I get a wierd printing error (not on google).

Is there anyway I can make a report to do this?

Thanks,
Bryan
 
Do you mind sharing:
- how you are attempting to dynamically set the control source
- the error message
 
Hi,

The error message is something like 'unable to set control
source while printing has started'

I'm attempted to set Me("txt1").ControlSource = rs!
fieldname.

Does this help?

Thanks,
Bryan
 
I'm not sure what you are attempting by setting the ControlSource to the
value stored in a field. Assuming txt1 is unbound, have you tried
Me("txt1").Value = rs!FieldName
 
I have a query determines what fields we want for each
particular report. The problem is when new fields are
added to the database I have to manually add hidden txt
boxes on the report. This is time consuming and not very
practical. I'm looking for a way to display any field
based on the query, which is why I'm setting the control
source of the text box.

Make any sense?

Thanks,
Bryan
 
I should have asked which event your code was running in. Have you tried
code in the On Open event of the report?

Also, I question solutions/applications that result in "new fields are added
to the database".
 
The code is ran On Open.

Unfortunately I have no control over the data. This report
shows information for various products, each with there
various extra information. Every month this data changes,
new products added for example, missing data, which is why
I'm trying to modify the report to be able to cope with
anything.

Thanks for all your help Duane, it is most appreciated.

Bryan
 
I just created a test report and ran it successfully with code like the
following. The field names don't contain spaces.
Private Sub Report_Open(Cancel As Integer)
Dim intFieldNum As Integer
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim fl As DAO.Field
Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT * FROM Customers")
For intFieldNum = 4 To 7
Me("txt" & intFieldNum).ControlSource = _
rs.Fields(intFieldNum).Name
Next
rs.Close
Set rs = Nothing
Set db = Nothing
End Sub
 
Back
Top