注册 登录
Office中国论坛/Access中国论坛 返回首页

5988143的个人空间 http://www.office-cn.net/?10050 [收藏] [复制] [分享] [RSS]

日志

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

已有 2656 次阅读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
 

发表评论 评论 (1 个评论)

回复 tmtony 2009-2-10 22:22
精彩! 好文!

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 注册

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-11-25 05:33 , Processed in 0.072753 second(s), 18 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

返回顶部