1,216
社区成员
发帖
与我相关
我的任务
分享
Public Sub ImageLoadPicture(pPictureBox As PictureBox)
Dim Bag As PropertyBag
Set Bag = New PropertyBag
Bag.WriteProperty "Image", pPictureBox.Image
Set DataReport3.Sections("Section1").Controls("Image1").Picture _
= Bag.ReadProperty("Image")
Set Bag = Nothing
End Sub
'报表中这样调用:
call ImageLoadPicture(chaxun.Picture2)
'Form1的代码
Private Sub Command1_Click()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim Sql As String
Dim i As Long
DataReport1.Orientation = rptOrientLandscape
'连接数据库(Access)
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0 ;" & _
"Data Source=" & App.Path & "\db1.mdb;" & _
"Persist Security Info=False"
'打开记录集
Set rs = New ADODB.Recordset
Sql = "select id,uname,age from tb where id = " & Text1.Text 'SQL返回一条记录(比如ID唯一)
rs.Open Sql, cn, adOpenKeyset, adLockOptimistic
'设置text的DataField控件属性
For i = 0 To rs.Fields.Count - 1
'细节中添加了与记录集字段相同数量的reptext控件
DataReport1.Sections("Section1").Controls.Item(i + 1).DataField = rs.Fields(i).Name
Next i
'设置报表数据源
Set DataReport1.DataSource = rs
DataReport1.Show
End Sub