crystal report

how can i changed the crystal reoprt control Orientation Property to landscape from vb5 code. I know its not possible from the control so is there any api function?
gali040898Asked:
Who is Participating?
 
majed100598Connect With a Mentor Commented:
1- print the report as file " vhange the destination to file"
2- set the printer object property to landscape
3- print the file
0
 
gali040898Author Commented:
I dont want to change the setting of the default printer.
I just want to print some of the report in landscape and other in portrait.
0
 
gali040898Author Commented:
I found that the function PESelectPrinter from crpe32.dll can make it . The last parameter is mode. if the mode is diffrent from 0 (i Set to 1) the function used the type DEVMODE which one of the arguments is 'dmOrientation'. I set this argument to 1 but i
am getting the error 'out of stack space'.
How to set the variable with type DevMode to success with the calling to the function PESelectPrinter when i want just to change the Orientation property?

0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
schildCommented:
You can try another idea
Before printing using the cystal report command, try to change the printer property like this

' start a printer sesion, but acualy do nothing
printer.print " "
printer.Orientation = vbPRORLandscape
' now you can try the Cystal report printing command

Hope that one of the two answers will help you :)

Good Luck
Schild
0
 
gali040898Author Commented:
Thank U but i try this befor and now again but it doesnt work.
I am getting an error 'Orientation' property cannot be set within a page'.

0
 
BergJCCommented:
Try this:
Declare Function Escape% Lib "GDI" (ByVal hDC%, ByVal nEsc%, ByVal nLen%, lpData As Any, lpOut As Any)

Const PORTRAIT = 1
Const LANDSCAPE = 2
Const GETSETPAPERORIENT = 30
Dim Orient As OrientStructure
Printer.Print "" 
Orient.Orientation = LANDSCAPE
x% = Escape(Printer.hDC, GETSETPAPERORIENT, Len(Orient), "", Null)  

0
 
BergJCCommented:
I forgot this part:

Type OrientStructure
   Orientation As Long
   Pad As String * 16
End Type
0
 
BergJCCommented:
Sheesh...I'm forgetful today. Here's the whole example:


In your Declarations:
Type OrientStructure
   Orientation As Long
   Pad As String * 16
End Type

' Enter the following Declare statement on one, single line:
Declare Function Escape% Lib "GDI" (ByVal hDc%, ByVal nEsc%, ByVal nLen%, lpData As OrientStructure, lpOut As Any)

In your code:

Const PORTRAIT = 1
Const LANDSCAPE = 2
Const GETSETPAPERORIENT = 30

Dim Orient As OrientStructure

'* Start the printer
Printer.Print ""

'* Specify the orientation
Orient.Orientation = LANDSCAPE

'* Send escape sequence to change orientation
x% = Escape(Printer.hDC, GETSETPAPERORIENT,Len(Orient), Orient, NULL)

'* The EndDoc will now re-initialize the printer
Printer.EndDoc


0
 
gali040898Author Commented:
BergJC hi,
I am getting the error "Method or datamember not found" in the line :
Orient.Orientation = LANDSCAPE
the type is exist in my  Declarations and when i try to see which data member belongs to Orient i found the two, so i dont know what is going wrong?
I didnt find the OrientStructure anywhere else but i found a diffrent escape function in win32api.txt :
Declare Function Escape Lib "gdi32" (ByVal hdc As Long, ByVal nEscape As Long, ByVal nCount As Long, ByVal lpInData As String, lpOutData As Any) As Long

Dont forget i am using vb5 on 32 bit.


0
 
BergJCCommented:
Gali,
     Would it be possible to save the reports you want to be landscape as landscape in the Crystal Development Environment and vice versa for the ones you want in portrait? I don't know how you are using the reports. If you go into File/Printer Setup (in Crystal) and change it to Landscape, then save the report, it will be landscaped. If you want to switch the same report between landscape and portrait, though, this will obviously not work. I thought I'd try the simple answer next.

BergJC
0
 
gali040898Author Commented:
BergJC hi,

The File/Printer Setup (in Crystal) is already Landscape but the printing is portrait.
Let me show u my code step:

' Printer Dialogbox
cdbOutputFile.ShowPrinter

after this commondialog box the Orientation is portrait ( i dont want the user to change the Orientation ) so i used this 3 lines to change the Orientation to landscape but it doesnt help, it still print in portrait mode.

If Printer.Orientation = 1 Then
        Printer.Orientation = vbPRORLandscape
End If

Then i set properties to crystal report control

CReport.Connect = "DSN = " & objIni.ACCESS_DSN
CReport.ReportFileName = objIni.FixedInvFrom
CReport.Destination = crptToPrinter
CReport.PrinterDriver = Printer.driverName
CReport.printerName = Printer.DeviceName
CReport.PrinterPort = Printer.Port
CReport.CopiesToPrinter = Printer.Copies
Result = CReport.PrintReport

0
 
BergJCCommented:
Try changing your code to:

If Printer.Orientation = 1 Then
     Printer.Print ""
     Printer.EndDoc
     Printer.Orientation = 2
End If
       
0
 
gali040898Author Commented:
BergJC hi,
I insert those lines befor and after the line :
cdbOutputFile.ShowPrinter
and it doesnt help .
try it befor the line and u will see that in commondialog box print
properties it still portrait.
0
 
BergJCCommented:
Gali,
     The reason it is still showing protrait in the common dialog is because changing the Printer.Orientation is only changing the settings for the current printer session only. It was my understanding that you didn't want to change the printer default settings. In order for your commondialog to show landscape, you will have to do this. I tried your code with the two extra lines I added and my Crystal Report came out landscaped. Unless you change the default printer settings, it will always show "portrait" in the common dialog. This is all the help I can give you with this one.

Take care,

BergJC
0
 
gali040898Author Commented:
BergJC hi,
I now  understand and i want to change just for the current session only.
where did you add the lines ,it is very strange that it isnt work for me.
0
 
BergJCCommented:
This is how I tried it and it printed landscape. Hopefully it will work for you.

' Printer Dialogbox
cdbOutputFile.ShowPrinter

If Printer.Orientation = 1 Then
     Printer.Print "" 
     Printer.EndDoc
     Printer.Orientation = 2
End If

CReport.Connect = "DSN = " & objIni.ACCESS_DSN
CReport.ReportFileName = objIni.FixedInvFrom
CReport.Destination = crptToPrinter
CReport.PrinterDriver = Printer.driverName
CReport.printerName = Printer.DeviceName
CReport.PrinterPort = Printer.Port
CReport.CopiesToPrinter = Printer.Copies
Result = CReport.PrintReport
0
 
BergJCCommented:
Did this work for you? Just curious....
0
 
gali040898Author Commented:
hi BergJc,
I Did the same as u and i dont know why it doesnt work for me.
0
 
BergJCCommented:
Try it in this order...

' Printer Dialogbox
cdbOutputFile.ShowPrinter

CReport.Connect = "DSN = " & objIni.ACCESS_DSN
CReport.ReportFileName = objIni.FixedInvFrom
CReport.Destination = crptToPrinter
CReport.PrinterDriver = Printer.driverName
CReport.printerName = Printer.DeviceName
CReport.PrinterPort = Printer.Port
CReport.CopiesToPrinter = Printer.Copies

If Printer.Orientation = 1 Then
     Printer.Print "" 
     Printer.EndDoc
     Printer.Orientation = 2
End If

Result = CReport.PrintReport

Put a break on "Result = CReport.PrintReport" and check the orientation property right before you send in to the printer (in the debug/immediate window). Make sure that the change is taking effect.
0
 
gali040898Author Commented:
BergJC hi,
I tryed this befor and i am realy thank u but it doesnt work.
the crystal report file is saved in landscape and the vb5 code looks the same.
I think that only using some api function in spite of i put some effort on this option also will work
0
 
majed100598Commented:
Dear gali what you ask about is not the correct way
you determine the type of the page landscape or portrait according to the report itself at design time so you dont need at run time to change the page

M_salah@hotmail.com
0
 
gali040898Author Commented:
Maged hi,
i have already done it but it doesn't help.
0
 
cedricdCommented:
Just had this
after saving your report in landscape

Crystal.ReportSource = crptReport
0
 
gali040898Author Commented:
thanks but it doesn't help it still print in portrait.
here is my vb5 code :
CReport.Connect = "DSN = " & objIni.ACCESS_DSN
CReport.ReportFileName = test
CReport.Destination = crptToPrinter
CReport.PrinterDriver = Printer.driverName
CReport.printerName = Printer.DeviceName
CReport.PrinterPort = Printer.Port
CReport.CopiesToPrinter = Printer.Copies
'
CReport.ReportSource = crptReport
'
Result = CReport.PrintRepor
0
 
cedricdCommented:
when you test the printing, set report.destination = crpttowindows (then you can change it to landscape i think) so you can see if it's in landscape or not and you don't print on paper.
so see my answer
0
 
cedricdCommented:
well,
you can try this.
first print into a file (set the report source to datacontrol, set the printfilename and the reportfilename)
second adjust the report created and save it in landscape
third retry my solution, if it doesn't work then perhaps print it into windows and then on the preview select the print button to change the mode (landscape).

-->    Crystal.SQLQuery = sql
       Crystal.ReportSource = crptReport
       Crystal.PrintFileType = crptCrystal
       Crystal.PrintFileName = Filename
       Crystal.ReportFileName = Filename
       Crystal.Destination = crpttowindow    
       Crystal.PrintReport
       Crystal.SQLQuery = ""


0
 
cedricdCommented:
try also to set the discardsaveddata to true on the crystal control propertie
0
 
gali040898Author Commented:
Hi,
I want to change to landscape from the code .
The *.rpt file is saved in landscape.
Now the user change to landscape in the print dialogbox i open for him befor  the printing to choose the printer.

0
 
cedricdCommented:
I think that if you want to program it with no print dialogbox, it will be easyer to make two crystal report (one in landscape and one not in landscape).It's easy to do and take less time.

0
 
gali040898Author Commented:
I dont understand.
i must have the dialogbox bec' the user have to choose the printer. i dont want that he will have to change to landscape or portrait two.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.