Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2004
    Posts
    4

    Unanswered: How do i print a .txt file with VBA?

    I have a text file named Inventory.txt, and i'm trying to send the file to the printer. How can i do this in code with VBA. For some reason the Printer.print command is giving me "Object doesn't support this property or method" along with Printer.EndDoc and ?Printer.NewPage?

    I saw these methods on the site and tried them but with Access 2003, none of them are available. Thank you in advance for any help you can offer.

    -Eric

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    441
    Hi!

    I haven't tried using any of the commands you're mentioning, but I think this should be possible using the ShellExecute API.

    Place the following in the declaration section of a module (at the top) if you place it in a standard module, change Private to Public:

    Private Declare Function apiShellExecute Lib "shell32.dll" _
    Alias "ShellExecuteA" _
    (ByVal hwnd As Long, _
    ByVal lpOperation As String, _
    ByVal lpFile As String, _
    ByVal lpParameters As String, _
    ByVal lpDirectory As String, _
    ByVal nShowCmd As Long) _
    As Long

    Then in the routine where you need to print, call it with:

    lngReturn = apiShellExecute(hWndAccessApp, "print", _
    strFileAndPath, vbNullString, vbNullString, 0)

    The declaration comes from http://www.mvps.org/access/api/api0018.htm, which is a nice wrapper for the ShellExecute API, also if you need to open other files.
    Roy-Vidar

  3. #3
    Join Date
    Nov 2004
    Posts
    4

    Thank you!

    Your code worked and now the print button actually prints. Is it possible to modify it to print the txt file in Landscape Mode vs Portrait Mode? Thank you for the speedy reply.

    - Eric

  4. #4
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    441
    I don't know whether it is possible or not. It is outside my little area of knowledge.

    I suspect, though, that to make this happen, you'd need to open the file in an application you can control from Access (for instance Word), then programaticly set the properties prior to printing.

    I'd be interested in seing if it was possible, though.
    Roy-Vidar

  5. #5
    Join Date
    Sep 2004
    Location
    Raleigh, NC
    Posts
    146
    You might try opening the document in it's native program and configuring the "Page Setup" to output the file exactly as you wish. Try printing again from Access and see if that works.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •