Private Sub PrintC_Click()
'Open the SQL connection
Set cn = New ADODB.Connection
'Concatenate string to connect to the SQL database
constring = "Provider=MSDASQL" & _
";Data Source=" & sqlDataSourceName & _
";User ID=" & userId & _
";Password=" & sqlPassword & _
";Initial Catalog=" & interCompanyId
With cn
.ConnectionString = constring
.CursorLocation = adUseNone
.Open
End With
strStartDate = Me.startdate & " 00:00:00"
strEndDate = Me.enddate & " 00:00:00"
strMORange = "," & Me.monumber & ","
Set rst = New ADODB.Recordset
strSQL = "execute dbo.test '" & strStartDate & "','" & strEndDate & "','" & strMORange & "'"
rst.Open strSQL, cn, adOpenDynamic, adLockOptimistic, adCmdText
Set crxReport = crxApplication.OpenReport(RPT1, 0)
crxReport.ParameterFields(1).SetCurrentValue (strStartDate)
crxReport.ParameterFields(2).SetCurrentValue (strEndDate)
crxReport.ParameterFields(3).SetCurrentValue (strMORange)
crxReport.Database.SetDataSource rst, 3, 1
crxReport.DiscardSavedData
crxReport.ReadRecords
CrystalReportViewer.CRViewer1.ReportSource = crxReport
CrystalReportViewer.Height = 400
CrystalReportViewer.Width = 600
CrystalReportViewer.CRViewer1.Top = 0
CrystalReportViewer.CRViewer1.Left = 0
CrystalReportViewer.CRViewer1.Height = 370
CrystalReportViewer.CRViewer1.Width = 580
CrystalReportViewer.CRViewer1.EnableGroupTree = False
CrystalReportViewer.CRViewer1.EnableRefreshButton = False
CrystalReportViewer.CRViewer1.ViewReport
CrystalReportViewer.Show
rst.Close
cn.Close
Set rst = Nothing
Set cn = Nothing
End Sub