Sad Der
accessd666 at yahoo.com
Fri Aug 15 02:27:26 CDT 2003
Hi group, I'm getting desperate. I need to finish a project at 16:00 cet because my plane flies at 18:00 AAAHHRG. I've created a function that creates a report. Of course now the users needs more reports. It can vary from 2-17(!) I keep getting the error: 2147 You must be in design view to create or delete controls. The error is correct because the line: Set rpt = CreateReport Creates a new report called "Report1" As you can see I tried giving the new report a name (using an extra param) but I could not get it to work. I also added the line: ' DoCmd.OpenReport strReportName, acViewDesign But this didn't work because it then adds the controls to the first report. I also tried adding report templates. I'm too f#$#ing stressed to see the solution, can anybody help me with this one? Below is the function. Thnx in advance SD Function CreateDynamicReport(strSql As String, strCaption As String, strTitle As String) Dim rpt As Report Dim txtNew As Access.TextBox Dim lblNew As Access.Label Dim rstSource As ADODB.Recordset Dim fldData As ADODB.Field Dim lngTop As Long Dim lngLeft As Long ' Return variable of data type Report pointing to ' new Report object. Set rpt = CreateReport '(CurrentDb, strReportName) 'Set properties for new report. With rpt .RecordSource = strSql .Caption = strCaption End With 'Restore new report. DoCmd.Restore lngLeft = 0 lngTop = 0 Set rstSource = New ADODB.Recordset rstSource.Open strSql, CurrentProject.Connection, adOpenForwardOnly ' Create corresponding label and text box controls for each field. ' DoCmd.OpenReport strReportName, acViewDesign For Each fldData In rstSource.Fields ' Create new text box control and size to fit data. Set txtNew = CreateReportControl("Report1", acTextBox, _ acDetail, , fldData.Name, lngLeft, lngTop) txtNew.SizeToFit 'Create title Set lblNew = CreateReportControl("Report1", acLabel, acPageHeader, _ , strTitle, 0, 0, 1400, 10) ' Create new label control and size to fit data. lblNew.FontSize = 12 lblNew.SizeToFit Set lblNew = CreateReportControl("Report1", acLabel, acPageHeader, _ , fldData.Name, lngLeft, lngTop + 1000, 1400, txtNew.Height) lblNew.FontBold = True lblNew.FontSize = 8 lblNew.SizeToFit ' Increment top value for next control. lngTop = lngTop '+ txtNew.Height lngLeft = lngLeft + txtNew.Width Next With rpt .Section(0).Height = 5 .Section(3).Height = 5 .Section(4).Visible = False End With DoCmd.OpenReport "Report1", acViewPreview rstSource.Close Set rpt = Nothing End Function __________________________________ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com