creating a report from a form

Eliot

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

My report is already created, but I need to create the textboxes by code 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! it won't work, and all the time it shows a -1 as a unique value. The labels are created great, but not the text boxes...

Also i would need to delete the text boxes in case they exist, and don't know how...

Thank you
 
Hey!

I got the solution, the problem was that all the textboxes where created on over the other, so i only could see the last one, that had as a value -1...

Solution: add a left margin everytime!
 

Users who are viewing this thread

Back
Top Bottom