vb6.0调用CrystalReport7报表,提示cannot open SQL Server
以下程序在运行时,在红色代码部分,提示cannot open SQL Server,但报表在CrystalReport中,是可以预览的,crptobj为水晶报表控件,代码如下:
Private Sub butPrint_Click()
On Error GoTo showerror
If Not IsDate(txtDateFm.Text) Or Not IsDate(txtDateTo.Text) Then
MsgBox "日期格式不对,日期格式为(MM/DD/YYYY)", vbOKOnly, "系统提示"
txtDateFm.SetFocus
Exit Sub
End If
crptobj.StoredProcParam(0) = txtbType.Text
crptobj.StoredProcParam(1) = txtDateFm.Text
crptobj.StoredProcParam(2) = txtDateTo.Text
crptobj.StoredProcParam(3) = Check1.Value
crptobj.StoredProcParam(4) = Check2.Value
crptobj.Action = 1
Exit Sub
showerror:
ShowErrMsg (Err.Description)
End Sub
Private Sub butQuit_Click()
Unload Me
End Sub
Private Sub Check1_Click()
If Check1.Value = 0 Then
Check2.Value = 0
Check2.Visible = False
Else
Check2.Value = 1
Check2.Visible = True
End If
End Sub
Private Sub Form_Load()
frmPrintTiaoMa.Height = Frame1.Height + 1300
frmPrintTiaoMa.Width = Frame1.Width + 400
frmPrintTiaoMa.Top = (Screen.Height - frmPrintTiaoMa.Height) / 4
frmPrintTiaoMa.Left = (Screen.Width - frmPrintTiaoMa.Width) / 2
crptobj.WindowState = crptMaximized
crptobj.WindowMinButton = False
txtDateFm.Text = "01/01/1900"
txtDateTo.Text = "12/31/2050"
crptobj.WindowLeft = 0
crptobj.WindowTop = 0
crptobj.ReportFileName = App.Path & "\report\tmReport.rpt"
crptobj.Connect = strRptDSN
crptobj.DiscardSavedData = True
End Sub