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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Binding controls on report open event

Status
Not open for further replies.

shadylane

Programmer
Jan 23, 2003
21
JP
Hello there,
I'm trying to create a report that is created dynamically when it is opened. There are 25 unbound text boxes and 25 unbound labels, named field1 - 25 and texttitle1 - 25 respectively. Each has it's 'visible' property set to false.
However, when I open it, all I get is 2 blank pages! No error appears and the query to which the report is tied to, contains data.
I guess I'm missing something.
Any pointers to a relevant post/help would be greatly appreciated.
Thanks!
Greg

Private Sub Report_Open()

Dim fieldno As Integer
Dim i As Integer
Dim addField As String
Dim addTitle As String

Dim db3 As DAO.Database
Dim rs3 As DAO.Recordset

Set db3 = CurrentDb()

Set rs3 = db3.OpenRecordset("qTempOutput")

fieldno = rs3.Fields.Count

For i = 1 To fieldno

addField = "field" & i
addTitle = "titletext" & i

Me(addField).ControlSource = rs3.Fields(i - 1).Name
Me(addField).Visible = True

Me(addTitle).Value = rs3.Fields(i - 1).Name
Me(addTitle).Visible = True

Next

Set db3 = Nothing
Set rs3 = Nothing

End Sub
 


Put your code in "On Format" event!

CUOK

 
Is that a report event?
I tried making it
Sub Report_OnFormat()

... but the results were the same.

In the VBA editor, when I select Report from the left hand (object?) pulldown, I only get the following events in the right hand (events?) pulldown.

Activate
Close
Deactivate
Error
NoData
Open
Page

I tried using Activate as well, but got an error message saying I should use the Open event.

... or do you mean the OnFormat event for each text box on the report? In which case, it would be a little late wouldn't it?

Thanks
Greg
 
U have to click on "Details" secstion then goto "on format" event!

SHOULD WORK.
GOOD LUCK
CUOK
 
Thanks cuok,
Seems to be OK with the Details_Format event now - except it's tripping up at this line.

Me(addField).ControlSource = rs3.Fields(i - 1).Name

When debugging, both the addfield variable and the contents of rs3.Fields(i - 1).Name are correct, which leads me to beleive that the problem is with 'ControlSource'.
Are there any problems setting this property in a report? Or can you only use it for forms?
Thanks
Greg
 
sorry for the delay!

options to try:
1 change Me(addField). to Me!addField.

2 did you checked the (i - 1) value?
3 dim i as VARIANT

can you send the comlete sub?

CUOK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top