Results 1 to 7 of 7

Thread: Print (VB6)

  1. #1
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Print (VB6)

    Hi

    I'm trying to print a document as follows:
    It doesn't work obviously, I thought this would be easy.
    Any help please !

    Dim strPath As String
    Dim strFile As String

    strPath = Me.txtPath
    strFile = Me.lstReports

    CommonDialog1.CancelError = True
    On Error Resume Next
    ' display the dialog
    CommonDialog1.ShowPrinter
    If Err.Number = 32755 Then Exit Sub ' user cancelled
    If CommonDialog1.Orientation = cdlLandscape Then
    Printer.Orientation = cdlLandscape
    Else
    Printer.Orientation = cdlPortrait
    End If

    With CommonDialog1
    .Print strPath & strFile
    End With

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Print (VB6)

    Hi Dave,

    Do you want to print the path or do you want to print the document?

    If you want to print the path, use
    <code>
    Printer.Print strPath & strFile
    Printer.EndDoc
    </code>
    The EndDoc method tells VB to actually send the data to the printer.

    If you want to print a document instead of its path, you can use ShellExecute, assuming that Windows "knows" how to print the file.

    Put the following declarations at the beginning of a module:
    <code>
    Private Declare Function ShellExecute 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

    Private Const SW_SHOWNORMAL = 1

    Public Sub PrintAFile(fn As String)
    Dim lngResult As Long
    lngResult = ShellExecute(0&, "Print", fn, 0&, 0&, SW_SHOWNORMAL)
    If lngResult <= 32 Then
    MsgBox "Something went wrong.", vbExclamation
    End If
    End Sub
    </code>
    Replace the bold lines with the following:
    <code>
    Call PrintAFile(strPath & strFile)
    </code>
    BTW are you sure that strPath always ends in a backslash?

  3. #3
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Print (VB6)

    Hans (Thanks)

    "BTW are you sure that strPath always ends in a backslash?"
    Yes I've hard coded that earlier in the coding.

    Your 2nd method works fine but doesn't show the print dialog !
    I'm presuming the default printer is used with the shellexecute method, giving the user no control..

    What if a user needs to print multiple copies ?

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Print (VB6)

    What kind of documents are you printing?

  5. #5
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Print (VB6)

    Hans

    They are PDF docs, fax headers and stuff, file names are loaded into a list box whilst the path is held in a text control.
    We can load the pdf into the control and have full control over the printer, but , I was just trying to bypass using the control.

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Print (VB6)

    I think you'll have to choose between automatic printing and having full control. VB6 doesn't "know" how to control the printing of external documents.

  7. #7
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Print (VB6)

    Hans

    Thanks once again for your expert advice, I'll use the quick print methos, if the user wants control then he'll have to load the pdf in the control as normal.

Posting Permissions

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