我的代码: Option Explicit Dim ypstr, tjstr, lsstr As String Dim hj As IntegerDim ypconn As New ADODB.Connection Dim cxset As ADODB.RecordsetDim Reportrk As New CrystalReport2 Dim Reportck As New CrystalReport4Private Sub Command1_Click()If Option1.Value = True Then '入库明细datestr = Mid(Format(Date, "YYYY-MM-DD"), 1, 4) + "." + Mid(Format(Date, "YYYY-MM-DD"), 6, 2) + "." + Mid(Format(Date, "YYYY-MM-DD"), 9, 2) tjstr = "select * from RKBF" End IfIf Option2.Value = True Then '出库明细 tjstr = "select * from CKBF" End Ifsjklj (tjstr)If Not cxset.EOF Then '药品库中有数据
If Text1.Text = "" Then If Check1.Value = 1 And Mid(cxset!日期, 6, 2) = Mid(Format(Date, "YYYY-MM-DD"), 6, 2) Or Check2.Value = 1 And Mid(cxset!日期, 1, 4) = Mid(Format(Date, "YYYY-MM-DD"), 1, 4) Or Check1.Value = 1 And Check2.Value = 1 And Mid(cxset!日期, 1, 7) = Mid(Format(Date, "YYYY-MM-DD"), 1, 7) Then
Reportrk.Database.SetDataSource cxset Screen.MousePointer = vbHourglass CRViewer91.ReportSource = Reportrk CRViewer91.ViewReport Screen.MousePointer = vbDefault End If Else If Check2.Value = 1 And Mid(cxset!日期, 6, 2) = Mid(Text1.Text, 6, 2) Or Check2.Value = 1 And Mid(cxset!日期, 1, 4) = Mid(Text1.Text, 1, 4) Or Check1.Value = 1 And Check2.Value = 1 And Mid(cxset!日期, 1, 7) = Mid(Text1.Text, 1, 7) Then
Reportck.Database.SetDataSource cxset Screen.MousePointer = vbHourglass CRViwer91.ReportSource = Reportck CRViewer91.ViewReport Screen.MousePointer = vbDefault End If
End If Else MsgBox " 数据库中没有数据,不能进行统计!", 0, "提示信息" End IfEnd Sub 在CRViewer91.ReportSource = Reportrk处报变量未定义。
2:启用Option Explicit
3: 应该跟这个注册没关系可能是因为某个地方写了crviewer91 ,但是调试的时候没走到这
但是编译的时候就检测到了。
Option Explicit
Dim ypstr, tjstr, lsstr As String
Dim hj As IntegerDim ypconn As New ADODB.Connection
Dim cxset As ADODB.RecordsetDim Reportrk As New CrystalReport2
Dim Reportck As New CrystalReport4Private Sub Command1_Click()If Option1.Value = True Then '入库明细datestr = Mid(Format(Date, "YYYY-MM-DD"), 1, 4) + "." + Mid(Format(Date, "YYYY-MM-DD"), 6, 2) + "." + Mid(Format(Date, "YYYY-MM-DD"), 9, 2)
tjstr = "select * from RKBF"
End IfIf Option2.Value = True Then '出库明细
tjstr = "select * from CKBF"
End Ifsjklj (tjstr)If Not cxset.EOF Then '药品库中有数据
If Text1.Text = "" Then
If Check1.Value = 1 And Mid(cxset!日期, 6, 2) = Mid(Format(Date, "YYYY-MM-DD"), 6, 2) Or Check2.Value = 1 And Mid(cxset!日期, 1, 4) = Mid(Format(Date, "YYYY-MM-DD"), 1, 4) Or Check1.Value = 1 And Check2.Value = 1 And Mid(cxset!日期, 1, 7) = Mid(Format(Date, "YYYY-MM-DD"), 1, 7) Then
Reportrk.Database.SetDataSource cxset
Screen.MousePointer = vbHourglass
CRViewer91.ReportSource = Reportrk
CRViewer91.ViewReport
Screen.MousePointer = vbDefault
End If
Else
If Check2.Value = 1 And Mid(cxset!日期, 6, 2) = Mid(Text1.Text, 6, 2) Or Check2.Value = 1 And Mid(cxset!日期, 1, 4) = Mid(Text1.Text, 1, 4) Or Check1.Value = 1 And Check2.Value = 1 And Mid(cxset!日期, 1, 7) = Mid(Text1.Text, 1, 7) Then
Reportck.Database.SetDataSource cxset
Screen.MousePointer = vbHourglass
CRViwer91.ReportSource = Reportck
CRViewer91.ViewReport
Screen.MousePointer = vbDefault
End If
End If
Else
MsgBox " 数据库中没有数据,不能进行统计!", 0, "提示信息"
End IfEnd Sub
在CRViewer91.ReportSource = Reportrk处报变量未定义。