With 數據環境.rsCommand名
If .State = adStateOpen Then .Close
.Source = SQL語句
.Open 打開想輸出的數據庫數據項以便輸出
End With
With 報表名
.DataSource=數據環境
.DataMember=Command名 這兩行也可固定設好而不必每次設置
設置頁表頭部分(RpttLabel…為報表控件名)
.Sections(2).Controls("RptLabelPage").Caption = "共%P頁第%p頁"
.Sections(2).Controls("RptLabelDate").Caption = "打印日期:%D"
.Sections(3).Controls("RptLabel1").Left=…
…
設置細節部分(RptShapeX、RptTextBoxX為報表控件名)
.Sections(3).Controls("RptShape1").Left=…
.Sections(3).Controls("RptShape1").Top=…
.Sections(3).Controls("RptShape1").Height=…
.Sections(3).Controls("RptShape1").Width=…
.Sections(3).Controls("RptTextBox1").DataMember=Command名
.Sections(3).Controls("RptTextBox1").DataField=字段1
.Sections(3).Controls("RptTextBox1").Font.Name=…
…
.Sections(3).Controls("RptShapeN").Visible=False
.Sections(3).Controls("RptTextBoxN").Visible=False
…
. Sections(3).Height=計算出的或固定的細節高度
動態調整報表標題(RptLabelTitle為報表標簽控件名)
.Sections(2). Controls("RptLabelTitle").Left=…
…
.Sections(2). Controls("RptLabelTitle").Alignment=…
…
調整完畢后
.Show 或 .PrintReport
End With
這樣做的優點是報表設計時簡單,調整方便、隨意,只需更改一點代碼,而不必為了一點點的修改而費神的在設計窗口調整半天。
原文轉自:http://www.anti-gravitydesign.com