Link to home
Start Free TrialLog in
Avatar of ArunAchudh
ArunAchudh

asked on

How to change printer orientation in VB?

hi al,

I have done a print sub routine which prints a data grid but the requirement is that the if the number of colums is more than 4 in the report the page orientatiob mst be in landscape.

how could i change the printer orientaion? how to ?

i tried
 Printer.Orientation = 2
also
 Printer.Orientation =vbPRORLandscape
but stil no help could i get from this.

please find the code snippet along with this
pLEASE suggest
With ctlGrid
       PTab = 19 'Set the first tab value
       Printer.Print vbCr;
       Printer.Print vbCr;
       Printer.Print vbCr;
       For J = 0 To .Columns.Count - 1
           .Col = J 'Set the current column
       
           'Send the field to the print line and add the tab.
           'Notice the semicolon at the end of the line.
           'Printer.Print Tab(PTab);
           Printer.FontBold = True
           Printer.Orientation = 2  'Here is what i tried to change orietnation for testing
           Printer.Print Tab(PTab); Trim$(.Columns(J).Caption);
       
           PTab = PTab + 37 'Increment the tab value
       Next
       Printer.Print
       Printer.Print vbCr;
       Printer.Print vbCr;
       Printer.Print vbCr;
       
       For I = 0 To .ApproxCount - 1
           PTab = 20 'Set the first tab value
           
           'This checks to see if a page break is needed
           If Printer.CurrentY + Printer.TextHeight(.Text) > Printer.ScaleHeight - 600 Then
                Printer.NewPage
                PTab = 19 'Set the first tab value
                Printer.Print vbCr;
                Printer.Print vbCr;
                Printer.Print vbCr;
                For J = 0 To .Columns.Count - 1
                    .Col = J 'Set the current column
                
                    'Send the field to the print line and add the tab.
                    'Notice the semicolon at the end of the line.
                    'Printer.Print Tab(PTab);
                    Printer.FontBold = True
                   
                    Printer.Print Tab(PTab); Trim$(.Columns(J).Caption);
                
                    PTab = PTab + 37 'Increment the tab value
                Next
                Printer.Print
                Printer.Print vbCr;
                Printer.Print vbCr;
                Printer.Print vbCr;
                
           End If
           Printer.Print
           PTab = 20    'set First Tab
           For J = 0 To .Columns.Count - 1
               .Col = J 'Set the current column
                
               'Send the field to the print line and add the tab.
               'Notice the semicolon at the end of the line.
               Printer.FontBold = False
               Printer.Print Tab(PTab); Trim$(.Text);
           
               PTab = PTab + 40 'Increment the tab value
           Next
           
           'After each column has printed to the print line
           'a Printer.Print statement without a semicolon will
           'will send the line to the printer and start a new
           'one.
           Printer.Print
           
           On Error Resume Next
           .Row = .Row + 1 'Set the active row
           On Error GoTo 0
           
       Next I
   End With
   Printer.EndDoc

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of jppinto
jppinto
Flag of Portugal image

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
Avatar of ArunAchudh
ArunAchudh

ASKER

but friend i have tried using priter.orirentation methhod too but the print fails.
Little help here pls
Friend got it..! The concept is that

printer.orientation has to be called before the first Print method is called.Else it would throw a runtime error.

Thanks for the support. Cool job dude.
Accepted
Solution identified