• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 754
  • Last Modified:

How do I change Notepad to print landscape using Access VBA

I need to print out a hardcopy of certian text files (.txt) in landscape.
So I need the VBA code to change the Notepad orientation and sometimes the left and right margins.
0
djMcCauley
Asked:
djMcCauley
  • 6
  • 6
  • 2
1 Solution
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
SendKeys is it; in other words, using that you send keystorkes just as if you were using the Notepad yourself.
JimD.
 
0
 
harfangCommented:
Why use Notepad to print text? It seems an Access report offers much better control.

I created a report with a single "can grow" text box called "Text". The code below reads a text file into the control. The name of the file could be an open argument of the report...

(°v°)
Dim varText As Variant
 
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    Text = varText
End Sub
 
Private Sub Report_Open(Cancel As Integer)
    
    Dim strLine As String
    
    varText = Null
    Open "C:\somewhere\something.txt" For Input As #1
    Do Until EOF(1)
        Line Input #1, strLine
        varText = varText + vbCrLf & strLine
    Loop
    Close #1
    
End Sub

Open in new window

0
 
djMcCauleyAuthor Commented:
Thanks for responding harfang.
I'm sorry, I have been called away to a meeting, but I will try your suggestion as soon as I return.
I should be back in about 2 hours from now (by 1:30pm-EST).
Please don't abandon me.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
harfangCommented:
I'm done for the day, but I might look in briefly tonight. -- (°v°)
0
 
djMcCauleyAuthor Commented:
Will you be around tomorrow morning?
0
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
<<Why use Notepad to print text? It seems an Access report offers much better control.>>
 Great idea!
JimD.
0
 
harfangCommented:
I'm here (home) for a while, then from work tomorrow (European time). Have you tried to create the report?

(°v°)
0
 
djMcCauleyAuthor Commented:
harfang,
Your code seems to work, but can you help me incorporate it into my code so the calling procedure can implement it as a hidden report. In other words, the user will not see the report come up each time.

Also need to set the report:
 to print in Landscape
 font size = 9
Left and Right Margins = 0.25

The calling procedure code (in a standard module):
Do Until rs.EOF
        Client = rs.Fields(0).Value
        invGrp = rs.Fields(1).Value
        inv = rs.Fields(2).Value
        invName = rs.Fields(3).Value
        outputPath = rs.Fields(5).Value
        outputType = rs.Fields(6).Value
        'rptType = rs.Fields(7).Value
       
         oFile = OutputFile(fileName, Client, invGrp, inv, invName, outputPath, rptType, outputType, rptDate)
           
            If outputType = "Print" Then
                Call PrintDoc(oFile)           ' This would be the call  to your code
            End If
        rs.MoveNext
Loop
0
 
harfangCommented:
The "call to PrintDoc" would just be

    DoCmd.OpenReport rptTextFile, acViewNormal, OpenArgs:=oFile

And the report (named rptTextFile here) open event opens the file with

    Open OpenArgs For Input As #1

instead of the fixed path and file name. As for changing the print parameters, simply design the text box to have the desired font face and size, and switch to "page setup" to select landscape and margins.

Tell me how that goes.

Cheers!
(°v°)
0
 
djMcCauleyAuthor Commented:
I'm getting the error: Variable Not Defined in the calling code (on rptTextFile)
rptTextFile is the name of the Report.

If outputType = "Print" Then
        'Call PrintDoc(oFile)
        DoCmd.OpenReport rptTextFile, acViewNormal, OpenArgs:=oFile       ' Compile error on rptTextFile
            End If
0
 
djMcCauleyAuthor Commented:
The error on the   DoCmd.OpenReport rptTextFile...   in the calling code has changed to:
 Run-time error 2497:
The action or method requires a Report Name argument.
0
 
harfangCommented:
Sorry, forgot the quotes: DoCmd.OpenReport "rptTextFile", ...

(°v°)
0
 
djMcCauleyAuthor Commented:
No Errors now. The problem was, I needed to enclose the ReportName in double quotes.
This seems to be the perfect solution to my problem.

Thanks so much!
David
0
 
harfangCommented:
Welcome and success with your reports! -- (°v°)
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 6
  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now