Expand|Select|Wrap|Line Numbers
- ------------------------------------------------------
- Public Sub PreviewReport_Click()
- createtNewReport
- End Sub
- ------------------------------------------------------
- Public Sub createtNewReport()
- Dim txtNew As TextBox
- Dim lblNew As Label
- Dim rpt As Report
- Dim sRptName As String
- Dim fldData As Field
- Dim lngTop As Long
- Dim lngLeft As Long
- Dim dbCurr As Database
- Dim rsRecordset As Recordset
- lngTop = 0
- lngLeft = 0
- -----------------------
- 'set report's record source propery
- 'rpt.RecordSource = "X"
- 'it gives an error saying that"Object variable or With block variable not set"
- 'with out this part the report's being created.
- ----------------
- Set dbCurr = DBEngine.Workspaces(0).Databases(0)
- Set rsRecordset = dbCurr.OpenRecordset("X")
- sRptName = "ICTA_PMIS_REPORT"
- DoCmd.OpenReport sRptName, acViewDesign
- For Each fldData In rsRecordset.Fields
- 'create controls
- Set txtNew = CreateReportControl(sRptName, acTextBox, acDetail, , fldData.Name, lngLeft + 1500, lngTop)
- txtNew.SizeToFit
- Set lblNew = CreateReportControl(sRptName, acLabel, acDetail, txtNew.Name, fldData.Name, lngLeft, lngTop, 1400, txtNew.Height)
- lblNew.SizeToFit
- 'Increment top calue for next control
- lngTop = lngTop + txtNew.Height + 25
- Next
- DoCmd.Close acReport, sRptName, acSaveYes
- '------------------------------------------------
- exit_createtNewReport:
- Exit Sub
- err_createtNewReport:
- MsgBox Err.Description
- Resume exit_createtNewReport
- End Sub