I Want To Know How I Can Connect To My Database In Crystal Reports. Which Option I Should Select? Database Is In Mssql Sever 2000.
Thnx In Advance
Printable View
I Want To Know How I Can Connect To My Database In Crystal Reports. Which Option I Should Select? Database Is In Mssql Sever 2000.
Thnx In Advance
you are going to have to make a ODBC connection to your SQL database.
Dim crApp As New CRAXDRT.Application
Dim crRe As New CRAXDRT.Report
Private Sub FormLoad()
Set crRe = crApp.OpenReport(App.Path & "\Report\customers.rpt")
LoadData
End Sub
Private Sub LoadData()
Dim cmdApp As Adodb.Command
Dim fld As FieldObject
Set cmdApp = New adodb.Command
cmdApp.ActiveConnection = Connect.cn
cmdApp.CommandTimeout = 15
cmdApp.CommandType = adCmdText
cmdApp.CommandText = "Select customerID, CustomerName from Customers Where CustomerCountry='VietNam'"
cmdApp.Execute
crRe.Database.AddADOCommand Connect.cn, cmdApp
Set fld = crRe.Sections(3).AddFieldObject("{ADO.customerID}", crRe.customerID.Left, crRe.customerID.Top)
SetFields fld, crRe.customerID.Font.Name, crRe.customerID.Font.Size, False, crRe.customerID.Height, crRe.customerID.Width, crRe.customerID.HorAlignment
Set fld = crRe.Sections(3).AddFieldObject("{ADO.customerName}", crRe.customerName.Left, crRe.customerName.Top)
SetFields fld, crRe.customerID.Font.Name, crRe.customerName.Font.Size, False, crRe.customerName.Height, crRe.customerName.Width, crRe.customerName.HorAlignment
Me.crCustomers.ReportSource = crRe
Me.crCustomers.ViewReport
Me.crCustomers.Zoom 75
End Sub
Private Sub SetFields(fld As FieldObject, fontName As String, fontSize As String, BoldStyle As Boolean, fieldHeight As Long, fieldWidth As Long, align As Long)
On Error GoTo bayloi
fld.Font = fontName
fld.TextFormat = crStandardText
fld.Font.Size = fontSize
fld.Font.Bold = BoldStyle
fld.Font.Italic = False
fld.TextColor = RGB(0, 0, 0)
fld.Height = fieldHeight
fld.Width = fieldWidth
fld.HorAlignment = align
Exit Sub
bayloi:
MsgBox "Err :" & Err.Number & vbNewLine & "Description :" & Err.Description & vbNewLine & "Source :" & Err.Source, vbInformation, "Error"
End Sub