Solved

crystal report

Posted on 1998-10-07
30
419 Views
Last Modified: 2013-12-26
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?
0
Comment
Question by:gali040898
  • 13
  • 9
  • 5
  • +2
30 Comments
 

Author Comment

by:gali040898
ID: 1487397
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
 

Author Comment

by:gali040898
ID: 1487398
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
 
LVL 2

Expert Comment

by:schild
ID: 1487399
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
 

Author Comment

by:gali040898
ID: 1487400
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
 
LVL 2

Expert Comment

by:BergJC
ID: 1487401
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
 
LVL 2

Expert Comment

by:BergJC
ID: 1487402
I forgot this part:

Type OrientStructure
   Orientation As Long
   Pad As String * 16
End Type
0
 
LVL 2

Expert Comment

by:BergJC
ID: 1487403
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
 

Author Comment

by:gali040898
ID: 1487404
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
 
LVL 2

Expert Comment

by:BergJC
ID: 1487405
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
 

Author Comment

by:gali040898
ID: 1487406
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
 
LVL 2

Expert Comment

by:BergJC
ID: 1487407
Try changing your code to:

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

Author Comment

by:gali040898
ID: 1487408
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
 
LVL 2

Expert Comment

by:BergJC
ID: 1487409
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
 

Author Comment

by:gali040898
ID: 1487410
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
 
LVL 2

Expert Comment

by:BergJC
ID: 1487411
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 2

Expert Comment

by:BergJC
ID: 1487412
Did this work for you? Just curious....
0
 

Author Comment

by:gali040898
ID: 1487413
hi BergJc,
I Did the same as u and i dont know why it doesnt work for me.
0
 
LVL 2

Expert Comment

by:BergJC
ID: 1487414
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
 

Author Comment

by:gali040898
ID: 1487415
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
 
LVL 2

Expert Comment

by:majed100598
ID: 1487416
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
 

Author Comment

by:gali040898
ID: 1487417
Maged hi,
i have already done it but it doesn't help.
0
 
LVL 2

Expert Comment

by:cedricd
ID: 1487418
Just had this
after saving your report in landscape

Crystal.ReportSource = crptReport
0
 

Author Comment

by:gali040898
ID: 1487419
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
 
LVL 2

Expert Comment

by:cedricd
ID: 1487420
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
 
LVL 2

Expert Comment

by:cedricd
ID: 1487421
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
 
LVL 2

Expert Comment

by:cedricd
ID: 1487422
try also to set the discardsaveddata to true on the crystal control propertie
0
 

Author Comment

by:gali040898
ID: 1487423
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
 
LVL 2

Expert Comment

by:cedricd
ID: 1487424
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
 

Author Comment

by:gali040898
ID: 1487425
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
 
LVL 2

Accepted Solution

by:
majed100598 earned 50 total points
ID: 1487426
1- print the report as file " vhange the destination to file"
2- set the printer object property to landscape
3- print the file
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now