Option ExplicitDim m_Report As New CrystalReport1' The ADO connection to the local database. Dim cnn1 As ADODB.Connection Dim datcmd1 As ADODB.Command' ************************************************************* ' Demonstrate the use of AddADOCommand by opening an ADO data command, ' adding the data source to the report, and then adding a field ' to the report that uses that data source. ' Private Sub cmdADO_Click() Dim fld As FieldObject Dim strCnn As String
' Open the data connection Set cnn1 = New ADODB.Connection strCnn = "Provider=MSDASQL;Persist Security Info=False;Data Source=Xtreme Sample Database;Mode=Read" cnn1.Open strCnn ' Create a new instance of an ADO command object Set datcmd1 = New ADODB.Command Set datcmd1.ActiveConnection = cnn1 datcmd1.CommandText = "Customer" datcmd1.CommandType = adCmdTable ' Add the datasource to the report m_Report.Database.AddADOCommand cnn1, datcmd1 ' Add a new field object to the report and set the field object to use ' the new data source. Set fld = m_Report.Section3.AddFieldObject("{ado.Customer Name}", 0, 0) LoadReport End Sub' ************************************************************* ' Demonstrate the use of AddOLEDBSource by opening an ADO data source, ' adding the data source to the report, and then adding a field ' to the report that uses that data source. In this example, the ' OLEDB source in the VB Data Environment is used ' Private Sub cmdOLEDB_Click() Dim fld As FieldObject
' Add the datasource to the report m_Report.Database.AddOLEDBSource DataEnvironment1.Connection1, "Customer" ' Add a new field object to the report and set the field object to use ' the new data source. Set fld = m_Report.Section3.AddFieldObject("{Customer.Customer Name}", 0, 0) LoadReport End Sub' ************************************************************* ' Load the Report in the viewer ' Private Sub LoadReport() Screen.MousePointer = vbHourglass CRViewer1.ReportSource = m_Report CRViewer1.ViewReport Screen.MousePointer = vbDefault cmdOLEDB.Enabled = False cmdADO.Enabled = False End Sub' ************************************************************* Private Sub cmdAbout_Click() frmAbout.Show vbModal End Sub' ************************************************************* Private Sub cmdExit_Click() Unload Me End Sub
Dim cnn1 As ADODB.Connection
Dim datcmd1 As ADODB.Command' *************************************************************
' Demonstrate the use of AddADOCommand by opening an ADO data command,
' adding the data source to the report, and then adding a field
' to the report that uses that data source.
'
Private Sub cmdADO_Click()
Dim fld As FieldObject
Dim strCnn As String
' Open the data connection
Set cnn1 = New ADODB.Connection
strCnn = "Provider=MSDASQL;Persist Security Info=False;Data Source=Xtreme Sample Database;Mode=Read"
cnn1.Open strCnn ' Create a new instance of an ADO command object
Set datcmd1 = New ADODB.Command
Set datcmd1.ActiveConnection = cnn1
datcmd1.CommandText = "Customer"
datcmd1.CommandType = adCmdTable ' Add the datasource to the report
m_Report.Database.AddADOCommand cnn1, datcmd1
' Add a new field object to the report and set the field object to use
' the new data source.
Set fld = m_Report.Section3.AddFieldObject("{ado.Customer Name}", 0, 0)
LoadReport
End Sub' *************************************************************
' Demonstrate the use of AddOLEDBSource by opening an ADO data source,
' adding the data source to the report, and then adding a field
' to the report that uses that data source. In this example, the
' OLEDB source in the VB Data Environment is used
'
Private Sub cmdOLEDB_Click()
Dim fld As FieldObject
' Add the datasource to the report
m_Report.Database.AddOLEDBSource DataEnvironment1.Connection1, "Customer"
' Add a new field object to the report and set the field object to use
' the new data source.
Set fld = m_Report.Section3.AddFieldObject("{Customer.Customer Name}", 0, 0)
LoadReport
End Sub' *************************************************************
' Load the Report in the viewer
'
Private Sub LoadReport()
Screen.MousePointer = vbHourglass
CRViewer1.ReportSource = m_Report
CRViewer1.ViewReport
Screen.MousePointer = vbDefault
cmdOLEDB.Enabled = False
cmdADO.Enabled = False
End Sub' *************************************************************
Private Sub cmdAbout_Click()
frmAbout.Show vbModal
End Sub' *************************************************************
Private Sub cmdExit_Click()
Unload Me
End Sub