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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening and running reports from VBA 2

Status
Not open for further replies.
Jun 17, 2004
50
GB
I am new to the objects in Crystal reports and I am having trouble even getting started opening and running from VBA.

I want to run a report that imports directly to an Excel spreadsheet via VBA.

When I use

Dim cryrep2 As CRAXDRT.Report

Set cryrep2 = cryapp.OpenReport("H:\WeeklyUpdates\EDdiversity\Test_ED_Div.rpt")

and then;

cryrep2.Export

I get the error after specifying how I want to export;
"Server has not yet been opened"

Crystal is looking at an Oracle database but when I try to open that using connection object of ADODB I get an error about tnsnames?

Is their something fundamental I am doing wrong (probably?!), does anyone know about any good books/resources on the subject?

Thanks in advance...
 
At the very least, you will need to declare an Application object and use that object's LogOnServer method to log on to the server where the Oracle database resides.

Try something like this:
Code:
Dim crxApp As New CRAXDRT.Application
Dim crxReport As CRAXDRT.Report

Set crxReport = crxApp.OpenReport("H:\WeeklyUpdates\EDdiversity\Test_ED_Div.rpt")

crxApp.LogOnServer "Your server LogOn Info"

With crxReport
    With .ExportOptions
        .DiskFileName = "YourFullExportPathIncludingFileName"
        .DestinationType = crEDTDiskFile
        'You may need to adjust the Excel settings here
        .FormatType = crEFTExcel80
    End With
    'Don't promt for export options
    .Export False
End With
    
crxApp.LogOffServer "Your server LogOn Info"

Set crxReport = Nothing
Set crxApp = Nothing

Also, you may want to look at Microsoft Query, which comes with most distributions of Excel. By using Crystal Reports to populate an Excel worksheet with data, you are using a middle man that you probably don't need.

-Gary
 
thanks Gary I tried this out but I get a different error message,

when I get to the line;

crxApp.LogOnServer "<my server logon string>"

I get the message;

"Server has not yet been opened".

I have put in all the details to my Oracle server inside the speech marks but it seems to need something else initialised before I can go past this step?
 
And you passed everything as a string value, including the password?

Perhaps you could post that line of code, and replace passwords, etc, with "abcd", or something like that.

I believe that the method states that userName and password are optional, but of course if the database requires it they really aren't.

-Gary
 
Thanks for your help on this Gary.

cryapp.LogOnServer "pdsora7.dll", "abc", "abc", "abcdefg", "abcdefg"

'cryapp.LogOnServer "provider = msdora;data source = abc;user id = abcdedfg;password = abcdefg"

I have to use the top line in my code as when I put it into one string I get the message that I have left out a required parameter (server name). "abc" is the server name "abcdefg" is the username and password (high security system this!).
 
And this reports runs fine from the Crystal design view, if you run it stand-alone?

-Gary
 
yeah the reports run ok. The first time you logon to the server you get the server logon and the report refreshes.

I have even tried to link directly to Oracle from Access using an ADO connection, this is when I got error messages about tnsnames.
 
Gary the solution to my problem was on the business objects support page, instead of using the logonserver method of the database I used the setlogoninfo method for the tables, the code you sent works a treat!!

Thanks very much!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top