Link to home
Start Free TrialLog in
Avatar of mmonir
mmonir

asked on

printing data report in landscape mode

Hi ,
 
 I just downloaded visual studio service pack 5.Now my forms are working fine when I try to print them in landscape mode but my Data report which has grouping feature is not working.I use different ways such as

  Printer.Orientation = vbPRORLandscape
  DataEnvironment1.cmReports_Grouping DataCombo1
  DataReport1.PrintReport
This time I got a printout with portrait mode but when I use
 Printer.Orientation = vbPRORLandscape
DataEnvironment1.cmReports_Grouping DataCombo1
 DataReport1.PrintForm
I did not even get a printout.
I want to mention that I am calling this data report from another form and when I use the following command,it is printing in portrait mode.

 DataEnvironment1.cmReports_Grouping DataCombo1
  DataReport1.PrintReport

Please send me some comments regarding this problem.Thanks in advance.
Avatar of twalgrave
twalgrave

Here's good information of the problem and resolution

http://archive.devx.com/premier/mgznarch/vbpj/1999/05may99/ap0599.pdf

Avatar of mmonir

ASKER

I have already read that article.but it didnot help me cause this article is talking about visual basic 5 and I have visual basic 6 service pack 5 and after installing this version my forms are working fine (printing in landscape mode),but data report is not printing in landscape mode.Anyway,thanks for trying to help me.
This article deals with the problems you explained you are experiencing in VB6.  What it is saying is that the datareport doesn't use the VB version of the printer oject when printing the report, so you must set the System default printer object if you want the printing to work properly.  Please reread the article, I think it will help (especially the sample code in Listing1).  If it doesn't help, sorry, that's all I got.
Avatar of mmonir

ASKER

I just tried and It gives me error saying "Sub or function not defined."
Did you copy the whole listing 1 (including the continued on)?  Oh never mind.  Her'es the code in it's entirety:

Private Sub Command1_Click()

    Dim iSaveOrient As Integer
    ' Save default printer's current
    ' orientation
    iSaveOrient = Printer.Orientation
   
    ' Set orientation to Landscape
    Call SetDefaultPrinterOrientation(vbPRORLandscape)
    '
    '  Display or print DataReport here 
    '
    ' Reset original orientation
    Call SetDefaultPrinterOrientation(iSaveOrient)

End Sub


'******************Put this in a module*************
Option Explicit
Public Enum PrinterOrientationConstants
OrientPortrait = 1
OrientLandscape = 2
End Enum
Private Type DEVMODE
dmDeviceName As String * 32
dmSpecVersion As Integer
dmDriverVersion As Integer
dmSize As Integer
dmDriverExtra As Integer
dmFields As Long
dmOrientation As Integer
dmPaperSize As Integer
dmPaperLength As Integer
dmPaperWidth As Integer
dmScale As Integer
dmCopies As Integer
dmDefaultSource As Integer
dmPrintQuality As Integer
dmColor As Integer
dmDuplex As Integer
dmYResolution As Integer
dmTTOption As Integer
dmCollate As Integer
dmFormName As String * 32
dmUnusedPadding As Integer
dmBitsPerPel As Integer
dmPelsWidth As Long
dmPelsHeight As Long
dmDisplayFlags As Long
dmDisplayFrequency As Long
End Type
Private Type PRINTER_DEFAULTS
pDataType As String
pDevMode As Long
DesiredAccess As Long
End Type
Private Type PRINTER_INFO_2
pServerName As Long
pPrinterName As Long
pShareName As Long
pPortName As Long
pDriverName As Long
pComment As Long
pLocation As Long
pDevMode As Long
pSepFile As Long
pPrintProcessor As Long
pDataType As Long
pParameters As Long
pSecurityDescriptor As Long
Attributes As Long
Priority As Long
DefaultPriority As Long
StartTime As Long
UntilTime As Long
Status As Long
cJobs As Long
AveragePPM As Long
End Type
Private Const DM_IN_BUFFER As Long = 8
Private Const DM_OUT_BUFFER As Long = 2
Private Const DM_ORIENTATION As Long = &H1
Private Const _
PRINTER_ACCESS_ADMINISTER As Long = &H4
Private Const PRINTER_ACCESS_USE As Long = &H8
Private Const _
STANDARD_RIGHTS_REQUIRED As Long = &HF0000
Private Const PRINTER_ALL_ACCESS = _
(STANDARD_RIGHTS_REQUIRED _
Or PRINTER_ACCESS_ADMINISTER Or _
PRINTER_ACCESS_USE)
Private Declare Sub CopyMemory Lib _
"kernel32" Alias "RtlMoveMemory" _
(hpvDest As Any, hpvSource As Any, _
ByVal cbCopy As Long)
Private Declare Function OpenPrinter _
Lib "winspool.drv" Alias _
"OpenPrinterA" (ByVal pPrinterName _
As String, phPrinter As Long, _
pDefault As Any) As Long
Private Declare Function ClosePrinter _
Lib "winspool.drv" (ByVal hPrinter As Long) As Long
Private Declare Function DocumentProperties Lib _
"winspool.drv" Alias _
"DocumentPropertiesA" (ByVal hWnd _
As Long, ByVal hPrinter As Long, _
ByVal pDeviceName As String, pDevModeOutput As Any, _
pDevModeInput As Any, ByVal fMode As Long) As Long
Private Declare Function GetPrinter _
Lib "winspool.drv" Alias "GetPrinterA" _
(ByVal hPrinter As Long, ByVal Level As Long, _
pPrinter As Any, ByVal cbBuf As _
Long, pcbNeeded As Long) As Long



Declare Function SetPrinter _
Lib "winspool.drv" Alias _
"SetPrinterA" (ByVal hPrinter As _
Long, ByVal Level As Long, _
pPrinter As Any, ByVal Command As _
Long) As Long
Function SetDefaultPrinterOrientation _
(ByVal eOrientation As _
PrinterOrientationConstants) As Boolean
Dim bDevMode() As Byte
Dim bPrinterInfo2() As Byte
Dim hPrinter As Long
Dim nSize As Long
Dim sPrnName As String
Dim dm As DEVMODE
Dim pd As PRINTER_DEFAULTS
Dim pi2 As PRINTER_INFO_2
' Get device name of default printer
sPrnName = Printer.DeviceName
' PRINTER_ALL_ACCESS required under
' NT, because we're going to call SetPrinter
pd.DesiredAccess = PRINTER_ALL_ACCESS
' Get a handle to the printer.
If OpenPrinter(sPrnName, hPrinter, pd) Then
' Get number of bytes requires
' for PRINTER_INFO_2 structure
Call GetPrinter(hPrinter, 2&, 0&, 0&, nSize)
' Create a buffer of the required size
ReDim bPrinterInfo2(1 To nSize) As Byte
' Fill buffer with structure
Call GetPrinter(hPrinter, 2, _
bPrinterInfo2(1), nSize, nSize)
' Copy fixed portion of structure into
' VB Type variable
Call CopyMemory(pi2, _
bPrinterInfo2(1), Len(pi2))
' Get number of bytes requires
' for DEVMODE structure
nSize = DocumentProperties(0&, _
hPrinter, sPrnName, 0&, 0&, 0)
' Create a buffer of the required size
ReDim bDevMode(1 To nSize)
' If PRINTER_INFO_2 points to a
' DEVMODE structure, copy it into our buffer
If pi2.pDevMode Then
Call CopyMemory(bDevMode( _
1), ByVal pi2.pDevMode, Len(dm))
Else
' Otherwise, call DocumentProperties to
' get a DEVMODE structure
Call DocumentProperties(0&, _
hPrinter, sPrnName, bDevMode(1), 0&, _
DM_OUT_BUFFER)
End If
' Copy fixed portion of structure
' into VB Type variable
Call CopyMemory(dm, bDevMode(1), Len(dm))
With dm
' Set new orientation
.dmOrientation = eOrientation
.dmFields = DM_ORIENTATION
End With
' Copy our Type back into buffer
Call CopyMemory(bDevMode(1), dm, Len(dm))
' Set new orientation
Call DocumentProperties(0&, hPrinter, sPrnName, _
bDevMode(1), bDevMode(1), DM_IN_BUFFER Or _
DM_OUT_BUFFER)
' Point PRINTER_INFO_2 at our modified DEVMODE
pi2.pDevMode = VarPtr(bDevMode(1))
' Set new orientation system-wide
Call SetPrinter(hPrinter, 2, pi2, 0&)
' Clean up and exit
Call ClosePrinter(hPrinter)
SetDefaultPrinterOrientation = True
Else
SetDefaultPrinterOrientation = False
End If
End Function
Avatar of mmonir

ASKER

Last time ,I did not include the all codes.but this time I did,And I did not get any error message but it is still printing in portrait mode.I included the private sub command in my form from where I am calling Data Report and rest of the code I put into my global module.If you have any suggestion,let me know.But lot of thanks for your help.
You are probably keeping the  following code in BEFORE you print the report:

<  ' Reset original orientation
   Call SetDefaultPrinterOrientation(iSaveOrient)>

This code will reset it back to portrait.  I have run this code myself and it works.  So simply call the Printreport before you call the
<  ' Reset original orientation
   Call SetDefaultPrinterOrientation(iSaveOrient)>
The code then looks like this:

Private Sub Command1_Click()

   Dim iSaveOrient As Integer
   ' Save default printer's current
   ' orientation
   iSaveOrient = Printer.Orientation
   
   ' Set orientation to Landscape
   Call SetDefaultPrinterOrientation(vbPRORLandscape)
   '
*********************************************
*********************************************
   ' — Display or print DataReport here —
*********************************************
*********************************************
   '
   ' Reset original orientation
   Call SetDefaultPrinterOrientation(iSaveOrient)

End Sub
Avatar of mmonir

ASKER

I think I tried the same way you told me.So,I am going to send you the code that I am using.And let me know if you have any suggestion.Thanks

lngProjectID = DataCombo1.Text
Dim iSaveOrient As Integer
 
  iSaveOrient = Printer.Orientation
  Call SetDefaultPrinterOrientation(vbPRORLandscape)

 
      DataEnvironment1.cmReports_Grouping DataCombo1
      DataReport1.PrintReport
      Unload DataReport1
  Call SetDefaultPrinterOrientation(iSaveOrient)

End Sub
Have you tried removing the line
DataEnvironment1.cmReports_Grouping DataCombo1 and see if it prints correctly?  Just trying to troubleshoot it.
Avatar of mmonir

ASKER

But If I remove that line,Data Report is not getting the parameter that I am trying to pass.Is there any other way,I can pass the parameter in the data report.Thanks
OK, let's take a step back.  Try creating a new project with a dataenvironment and a data report. No parameters, just a simple "select * from table".  Hardcode everything (I.e. don't set properties in code, use the properties in the IDE).  Then copy/paste the code I provided and run the test.  Does it come out in Landscape?  I'm trying to eliminate anything else happening in your project that's blocking the landscape printing.
Avatar of mmonir

ASKER

Nope! I just created a data report and data environment and in the property of data environment I just choose one table.And then try to print but still I am getting portrait mode.But If I try to print a form in landscape,it works fine.
Well, I'm out of ideas.  When I perform the same, I get the report in landscape.  I hope someone can help.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in Community Support that this question is:
- refund and close
Please leave any comments here within the
next seven days.
ASKER CERTIFIED SOLUTION
Avatar of Mindphaser
Mindphaser

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial