使用vba代码,将记录添加到现有报告的详细信息部分

时间:2016-04-07 20:46:55

标签: vba adodb

我正在尝试将记录添加到现有报告的详细信息部分。数据显示在设计视图中,但不显示在报告中。该报告显示空白字段。此外,如果我希望每个字段都有黑色边框,我如何在vba代码中执行此操作以下是我的代码:     Dim stDocName As String     Dim db As Database     Dim rs As Recordset     Dim rs2作为Recordset     Dim sSQL As String     Dim fld作为DAO.Field的记录集字段     Dim txtNew As Access.TextBox'文本框控件     Dim rpt As Report'保持报告对象     Dim lngTop As Long'掌握控制位置的最高价值     Dim lngLeft As Long'保持控制位置的左侧值     昏暗的位置As Long

' initialise position variables
lngLeft = 0
lngTop = 0

'Create the report
'Set rpt = CreateReport

stDocName = "rptInvoice"
DoCmd.OpenReport stDocName, acViewDesign

sSQL = "Select SOWCode, SowDescription, Qty, Rate, SOWTotal from tbltmpInvoice"

' set properties of the Report

'用rpt '。宽度= 8500 '.RecordSource = sSQL '结束

Set db = CurrentDb()
Set rs = db.OpenRecordset(sSQL)

'Count all records in the table tblCompany
rs.MoveLast
rs.MoveFirst

location = location + 900

Read_Records:

' Create corresponding label and text box controls for each field.
For Each fld In rs.Fields

    ' Create new text box control and size to fit data.
    Set txtNew = CreateReportControl(stDocName, acTextBox, _
    acDetail, , fld.Value, location, lngTop)
    'txtNew.SizeToFit

    'Relocate text field
    location = location + 1000

Next

DoCmd.Close

' Increment top value for next control
'lngTop = lngTop + txtNew.Height + 25

stDocName = "rptInvoice"
DoCmd.OpenReport stDocName, acViewPreview

'DoCmd.Close

0 个答案:

没有答案