create a report from a form

Eliot

New member
Local time
Today, 07:07
Joined
Dec 18, 2007
Messages
8
Hello,

i need to create a report from a form. I found a way to do it in the microsoft site, but no way to have it working. My code is the following:

DoCmd.OpenReport "test4", acViewDesign
Set rpt = Reports![test4]
Set rcset = CodeDb.OpenRecordset(querystring)
rpt.RecordSource = querystring

prevcolwith = 0
lblCol = 0

'creating headers
For i = 0 To rcset.Fields.Count - 1
Set labNew = CreateReportControl(rpt.name, acLabel, acPageHeader, , rcset.Fields(i).name, lblCol)
labNew.SizeToFit
lblCol = lblCol + 600 + labNew.Width
Next

'creating details
lngLeft = 0
lngTop = 0
For i = 0 To rcset.Fields.Count - 1
Set txtNew = CreateReportControl(rpt.name, acTextBox, acDetail, , , lngLeft + 15 + prevColwidth, lngTop)
txtNew.SizeToFit
txtNew.ControlSource = rcset(i).name
prevcolwith = prevcolwith + txtNew.Width

Next

'DoCmd.Save

stDocName = "test4"
DoCmd.OpenReport stDocName, acPreview


Am i missing something?? As it is not working, and it should work!

Thank you
 
I've never bothered to create a report dynamically (can't see why I'd need to), but for anyone to help you, the specifics of why it's not working would be helpful. Do you get an error? If so, what is it? What line does the code break on? What happens/doesn't happen?
 

Users who are viewing this thread

Back
Top Bottom