应该没有问题,下面是将MSFlexGrid1里的内容导出到4.6的水晶报表当中的代码 Private Sub cmdPrint_Click() Dim PUBmdb As New ADODB.Connection '报表数据库连接变量 Dim StrSql As String Dim str_mdb As String Dim PUBRS As New ADODB.Recordset Dim i, j As Integer CrystalReport1.ReportFileName = App.Path & "\phbb.rpt" str_mdb = "Driver={Microsoft Access Driver (*.mdb)};Uid=;Pwd=;Dbq= " & App.Path & "\Report.mdb" PUBmdb.Open str_mdb PUBmdb.Execute "delete * from Report" StrSql = "select * from Report" PUBRS.Open StrSql, PUBmdb, adOpenKeyset, adLockPessimistic If Trim(MSFlexGrid1.TextMatrix(1, 0)) <> "" Then For i = 1 To MSFlexGrid1.Rows - 1 PUBRS.AddNew For j = 0 To MSFlexGrid1.Cols - 1 If Trim(MSFlexGrid1.TextMatrix(i, j)) <> "" Then PUBRS.Fields(j) = Trim(MSFlexGrid1.TextMatrix(i, j)) End If Next PUBRS.Update Next End If '指定报表模板的数据来源 CrystalReport1.DataFiles(0) = App.Path & "\Report.mdb" CrystalReport1.Formulas(1) = "CXRQ= '(" & DTPicker1.Value & "至" & DTPicker2.Value & ")'" On Error GoTo Prnerr: CrystalReport1.Action = 1 PUBRS.Close PUBmdb.Close Exit Sub
Prnerr: MsgBox "打印机错误!", vbExclamation, "系统提示" Exit Sub
End Sub
//能不能把一行高度设出来,然后字段只在那个空间里,如果多出了也不会把报表撑开?可以設置它的行數最大值: 單擊右鍵-->Format Field-->Can Grow-->Maxinum number of lines = (最大行數)
Private Sub cmdPrint_Click()
Dim PUBmdb As New ADODB.Connection '报表数据库连接变量
Dim StrSql As String
Dim str_mdb As String
Dim PUBRS As New ADODB.Recordset
Dim i, j As Integer
CrystalReport1.ReportFileName = App.Path & "\phbb.rpt"
str_mdb = "Driver={Microsoft Access Driver (*.mdb)};Uid=;Pwd=;Dbq= " & App.Path & "\Report.mdb"
PUBmdb.Open str_mdb
PUBmdb.Execute "delete * from Report"
StrSql = "select * from Report"
PUBRS.Open StrSql, PUBmdb, adOpenKeyset, adLockPessimistic
If Trim(MSFlexGrid1.TextMatrix(1, 0)) <> "" Then
For i = 1 To MSFlexGrid1.Rows - 1
PUBRS.AddNew
For j = 0 To MSFlexGrid1.Cols - 1
If Trim(MSFlexGrid1.TextMatrix(i, j)) <> "" Then
PUBRS.Fields(j) = Trim(MSFlexGrid1.TextMatrix(i, j))
End If
Next
PUBRS.Update
Next
End If '指定报表模板的数据来源
CrystalReport1.DataFiles(0) = App.Path & "\Report.mdb"
CrystalReport1.Formulas(1) = "CXRQ= '(" & DTPicker1.Value & "至" & DTPicker2.Value & ")'"
On Error GoTo Prnerr:
CrystalReport1.Action = 1
PUBRS.Close
PUBmdb.Close
Exit Sub
Prnerr:
MsgBox "打印机错误!", vbExclamation, "系统提示"
Exit Sub
End Sub
單擊右鍵-->Format Field-->Can Grow-->Maxinum number of lines = (最大行數)