I am writing a VB app that provides the user with a menu of reports written in Crystal Reports 4.6. When the user selects a report, it is shown in the Crystal Reports preview window from where it can be printed to the selected printer.

My problem is that the page orientation is derived from the printer, not the report. I need the orientation to be portrait or landscape depending on the report selected, not the printer. If the selected printer is set up as portrait but the report is landscape, I need it to print in landscape (and vice versa). I don't want the user to have to touch the printer setup.

I have found the following code segment that looks like it might be a solution:

Dim repApp As CRAXDRT.Application
Dim cryReport As CRAXDRT.Report
Set cryReport = repApp.OpenReport(strRptName, 1) 'where strRptName has been set up as the report name
cryReport.PaperOrientation = crLandscape

However, it gives me a "User-defined type not defined" error on compile. I need to know how to make it work so that I can test it. Or if you don't think it's the solution I need, perhaps you have some other suggestions?

Thanks!

Recommended Answers

All 5 Replies

Dim repApp As CRAXDRT.Application
Dim cryReport As CRAXDRT.Report

You need to set a new instance of repApp and cryReport...

Dim repApp As CRAXDRT.Application
Dim cryReport As CRAXDRT.Report

Set repApp = New CRAXDRT.Application
Set cryReport = New CRAXDRT.Report

Thanks for your reply, but how do I get around the User-defined type not defined" compilation error?

The "User-defined type not defined" error occurs on this line:

Dim repApp As CRAXDRT.Application

Making a change to a later line won't alter the fact that it doesn't compile.

Hi,
Code you are using is for Higher Versions...
For CR4.6, Add Crystal Reports OCX Control on the Form.
And Use This Code:

With CrystalReport1
    .ReportFileName = App.Path & "\MyRpt.Rpt"
    .Action = 1
End With

Regards
Veena

Thanks for the tip, QVeen72. I won't pursue that option any more.

I'm already using the code you have provided, so it isn't the solution to my problem. The report selected by the user appears in the preview window, but always with the page orientation setting of the printer, not the report. I need it to ignore the page orientation setting of the priner and use the setting in the report.

Thanks for trying, though, Please let me know if you have any other ideas...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.