Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
'Variables to use to connect to database
Dim cn As ADODB.Connection
Dim userinfo As New RetrieveGlobals.retrieveuserinfo 'new object of RetrieveGlobals.retrieveuserinfo type
Dim interCompanyId As String
Dim userId As String
Dim sqlPassword As String
Dim sqlDataSourceName As String
Dim constring As String
Dim rst As ADODB.Recordset
Dim cmd As ADODB.Command
Dim strSQL As String
'Public CRViewer1 As New CRViewer
Public crxApplication As New CRAXDRT.Application
Public crxReport As New CRAXDRT.Report
Private Sub btnPrint_Click()
If crwApplication Is Nothing Then
Set crwApplication = CreateObject("Crystal.CRPE.Application")
End If
'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
Set rst = New ADODB.Recordset
strWCPN = VBA.Trim$(Me.ItemNumber)
strSQL = "execute dbo.GPD_Select_ItemMPN" & " '" & strWCPN & "'"
rst.Open strSQL, cn, adOpenDynamic, adLockOptimistic, adCmdText
Set crxReport = crxApplication.OpenReport("d:\MPNReport.rpt", 0)
crxReport.ParameterFields(1).SetCurrentValue (Me.ItemNumber)
crxReport.Database.SetDataSource rst, 3, 1
crxReport.DiscardSavedData 'chuck out old data
crxReport.ReadRecords 'reads the record without actually calling the printer
'crxReport.PrintOut 'calls the printer
CrystalReportViewer.CRViewer1.ReportSource = crxReport ' set crystal report source
'set dimension of the form where the crsytal report control is placed
CrystalReportViewer.Height = 550
CrystalReportViewer.Width = 750
'set dimension for crystal report viewer
CrystalReportViewer.CRViewer1.Top = 0
CrystalReportViewer.CRViewer1.Left = 0
CrystalReportViewer.CRViewer1.Height = 500
CrystalReportViewer.CRViewer1.Width = 700
CrystalReportViewer.CRViewer1.EnableGroupTree = False 'disable group tree button
CrystalReportViewer.CRViewer1.EnableRefreshButton = False ' disable refresh button
CrystalReportViewer.CRViewer1.ViewReport 'brings up crystal report in preview mode
CrystalReportViewer.Show 'show the form where the crystal report control is placed
rst.Close
cn.Close
Set rst = Nothing
Set cn = Nothing
End Sub
'RetrieveGlobals
sqlDataSourceName = userinfo.sql_datasourcename()
userId = userinfo.retrieve_user()
sqlPassword = userinfo.sql_password()
interCompanyId = userinfo.intercompany_id()
Private Sub cmdPrint_Click()
Dim i As Integer
On Error GoTo Error_Handler
For i = 1 To mRowCount
Debug.Print "row count" & mRowCount
If mDataArray(i).intLabel > 0 Then
Set crsReport1 = crxApplication.OpenReport(RPT1, 0)
Set crsReport2 = crxApplication.OpenReport(RPT2, 0)
'crsReport1.FormulaFields.Item(1).Text = Chr$(39) & mDataArray(i).strbarcode & Chr$(39)
crsReport1.FormulaFields.Item(1).Text = Chr$(39) & "PO#: " & strPONumber & Chr$(39)
crsReport1.FormulaFields.Item(2).Text = Chr$(39) & mDataArray(i).strbarcode & Chr$(39)
'crsReport1.PrintOut False, mDataArray(i).intLabel
crsReport2.FormulaFields.Item(1).Text = Chr$(39) & CStr(CLng(mDataArray(i).fltQty)) & Chr$(39)
'crsReport2.PrintOut False, mDataArray(i).intLabel
crsReport1.DiscardSavedData 'chuck out old data
crsReport1.ReadRecords 'reads the record without actually calling the printer
'crsReport1.PrintOut 'calls the printer
CrystalReportViewer.CRViewer1.ReportSource = crsReport1 ' set crystal report source
'set dimension of the form where the crsytal report control is placed
CrystalReportViewer.Height = 380
CrystalReportViewer.Width = 580
'set dimension for crystal report viewer
CrystalReportViewer.CRViewer1.Top = 0
CrystalReportViewer.CRViewer1.Left = 0
CrystalReportViewer.CRViewer1.Height = 400
CrystalReportViewer.CRViewer1.Width = 600
CrystalReportViewer.CRViewer1.EnableGroupTree = False 'disable group tree button
CrystalReportViewer.CRViewer1.EnableRefreshButton = False ' disable refresh button
CrystalReportViewer.CRViewer1.ViewReport 'brings up crystal report in preview mode
CrystalReportViewer.Show 'show the form where the crystal report control is placed
crsReport2.DiscardSavedData 'chuck out old data
crsReport2.ReadRecords 'reads the record without actually calling the printer
'crsReport2.PrintOut 'calls the printer
crystalReportViewer2.CRViewer1.ReportSource = crsReport2 ' set crystal report source
'set dimension of the form where the crsytal report control is placed
crystalReportViewer2.Height = 380
crystalReportViewer2.Width = 580
'set dimension for crystal report viewer
crystalReportViewer2.CRViewer1.Top = 0
crystalReportViewer2.CRViewer1.Left = 0
crystalReportViewer2.CRViewer1.Height = 400
crystalReportViewer2.CRViewer1.Width = 600
crystalReportViewer2.CRViewer1.EnableGroupTree = False 'disable group tree button
crystalReportViewer2.CRViewer1.EnableRefreshButton = False ' disable refresh button
crystalReportViewer2.CRViewer1.ViewReport 'brings up crystal report in preview mode
crystalReportViewer2.Show 'show the form where the crystal report control is placed
End If
Next
Exit Sub
End Sub