Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling a Crystal Report(looking at SQL Server) from VBA

Status
Not open for further replies.

ihaveaproblem

Programmer
Jul 4, 2003
14
GB
Can anybody help!

I am trying to call a Crystal report and export it from access(as i don't have VB6). I have managed to conncect to the report but when I run the export command it asks me to save the file but then says "server not yet started"

the crystal report access a SQLServer database, so i presume I need to attach to this prior to running the report, howver this is where I am stuck. I have opened a new ADO Connection toSQLSERVER, but i'm not sure what other commands to use in order to connect the report to the SQL datasource. Does anyboy have a solution??

The code I have so far is as follow:-


Const RepFilename = "G:\Crystal Reports\RepExport.rpt"
Public Function LaunchReport(ByRef RepFilename As String) As Integer

Dim crApp As CRPEAuto.Application
Dim crRep As CRPEAuto.Report
Dim crDB As CRPEAuto.Database
Dim crDBTables As CRPEAuto.DatabaseTables

On Error GoTo LaunchReportError



'Open Database
Dim CPLDB As ADODB.Connection
Set CPLDB = New ADODB.Connection
CPLDB.Open "PROVIDER=SQLOLEDB.1; SERVER=DATASQL6;PASSWORD=;USER ID=Tuser;INITIAL CATALOG=;"


'Check if Report Exists
If Dir$(CPLFilename) = "" Then
Err.Raise 1, "CrystalOpenReport", "Report name: " & RepFilename & " does not exist."

End If


On Error Resume Next
Set crApp = GetObject(, "Crystal.CRPE.Application")
If Err.Number > 0 Then
Set crApp = CreateObject("Crystal.CRPE.Application")
End If


Set crRep = crApp.OpenReport(RepFilename)
Set crDB = crRep.Database
Set crDBT = crDB.Tables

'THIS COMMAND EXECUTES BUT NO DATA IS FOUND DUE TO LACK OF CONNECTION TO SQLSERVER!!! I NEED HELP!!
crRep.Export



LaunchReportError:
Set crRep = Nothing
MsgBox Err.Description, vbExclamation, "Error"
Exit Function
End Function
Private Sub Command0_Click()
Call LaunchReport(RepFilename)
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top