注冊 登錄
Office中國論壇/Access中國論壇 返回首頁

5988143的個人空間 http://www.mzhfr.cn/?10050 [收藏] [復(fù)制] [分享] [RSS]

日志

Set Record Source,controls And Display Data In A Report Using VBA Code

已有 2830 次閱讀2009-2-10 12:29 |個人分類:雜誌|

Option Compare Database
'------------------------------------------------------
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
 

發(fā)表評論 評論 (1 個評論)

回復(fù) tmtony 2009-2-10 22:22
精彩! 好文!

facelist doodle 涂鴉板

您需要登錄后才可以評論 登錄 | 注冊

QQ|站長郵箱|小黑屋|手機版|Office中國/Access中國 ( 粵ICP備10043721號-1 )  

GMT+8, 2025-7-17 00:29 , Processed in 0.071345 second(s), 18 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

返回頂部