Results 1 to 6 of 6

Thread: printing from VB

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2000
    Posts
    24

    Question printing from VB within Access '97

    I know that the following code will print data to a file. How can I have the same data sent directly to a printer?
    ---------------------------------------------------
    Private Sub Command3_Click()

    Dim intCount As Integer, strCount As String

    Open "TESTFILE" For Output As #1

    intCount = 1

    Do While intCount < 11
    Print #1, "This is line "; strCount
    intCount = intCount + 1
    Loop

    Close #1

    End Sub
    ---------------------------------------------------

    Any assistance would be appreciated.



  2. #2
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    In a very similar way.

    Code:
    Dim intCount As Integer, strCount As String
    intCount = 1
    Do While intCount < 11
      Printer.Print "This is line "; strCount
      intCount = intCount + 1
    Loop
    'tells the page to be sent
    Printer.EndDoc
    
    
    'or this may work
    Shell "copy TESTFILE Lpt1"
    Iain, thats with an i by the way!

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2000
    Posts
    24
    lain,

    When I tried using Printer.print I received a Compile error: Variable not defined. It then hi-lited the Printer portion of Printer.print. How do I define the Printer?

  4. #4
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    The Printer object of VB is a global object. Like the Screen object or the App object.

    There is no need to define it. I am not really sure what is wrong, it should compile, even if you do not actually have a printer installed.

    Sorry to insult you by asking, but you did spell it right didn't you? Other than that, what version of VB do you have?
    Iain, thats with an i by the way!

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Sep 2000
    Posts
    24
    iain,

    No insult taken. I'm prone to mistakes like anyone else. However, I did spell it correctly. I did, however, fail to mention that I was using VB through Microsoft Access '97. Don't know if that makes a difference or not.

    ern

  6. #6
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    Well that is the problem then.

    I dont have access up and running, so i cant really help much. I had a quick look in word, which i think has simialr objects, and there was no printer object.

    What i have managed to gather is there is a

    Report.Print Method
    and a
    DoCmd.PrintOut Method

    Try looking at those. Otherwise, maybe someone else can help. Sorry i couldnt help more.
    Iain, thats with an i by the way!

Posting Permissions

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



Click Here to Expand Forum to Full Width