We help IT Professionals succeed at work.
Get Started

How to change printer orientation in VB?

ArunAchudh
ArunAchudh asked
on
2,094 Views
Last Modified: 2013-12-20
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

Comment
Watch Question
Commented:
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE