你可以在程序中动态设置数据环境的command的数据来源简单示例下列代码引用自 lxqlogo0(群子) Private Sub Command3_Click() Dim objcon As New ADODB.Connection Dim objrs As New ADODB.Recordset objcon.Open "provider=sqloledb.1;user id=sa;password=csm@csm;datasource=;initial catalog=xiazaijiluziliao" objrs.Open "select * from table where name='& text1.text & "'", objcon, 1, 3 Set DataGrid1.DataSource = objrs.DataSource 'Me.Caption = objrs.RecordCount Set DataReport1.DataSource = DataGrid1.DataSource 'DataReport1.DataMember = DataGrid1.DataMember With DataReport1 .Sections(4).Controls("Label2").Caption = "共%P页第%p页" .Sections(2).Controls("label3").Caption = "打印日期:%d %t"'.Sections(3).Controls("Text1").DataMember = objrs.DataMember .Sections(3).Controls("Text1").DataField = "ziduan1" .Sections(3).Controls("Text2").DataField = "ziduan2" .Sections(3).Controls("Text3").DataField = "ziduan3" End With DataReport1.ShowEnd Sub
Private Sub Command3_Click()
Dim objcon As New ADODB.Connection
Dim objrs As New ADODB.Recordset
objcon.Open "provider=sqloledb.1;user id=sa;password=csm@csm;datasource=;initial catalog=xiazaijiluziliao"
objrs.Open "select * from table where name='& text1.text & "'", objcon, 1, 3
Set DataGrid1.DataSource = objrs.DataSource
'Me.Caption = objrs.RecordCount
Set DataReport1.DataSource = DataGrid1.DataSource
'DataReport1.DataMember = DataGrid1.DataMember
With DataReport1
.Sections(4).Controls("Label2").Caption = "共%P页第%p页"
.Sections(2).Controls("label3").Caption = "打印日期:%d %t"'.Sections(3).Controls("Text1").DataMember = objrs.DataMember
.Sections(3).Controls("Text1").DataField = "ziduan1"
.Sections(3).Controls("Text2").DataField = "ziduan2"
.Sections(3).Controls("Text3").DataField = "ziduan3"
End With
DataReport1.ShowEnd Sub
这句不好用,提示下标越界