Solved

VB 6.0 Report, User Printer Selection

Posted on 2004-10-28
163 Views
Last Modified: 2010-05-02
I have an APP with several VB 6.0 reports, one of which is called 'rptMainInfo'.  I currently have logic that allows the user to select whether they want to view the report on the screen or send it to the printer.  Based on thier response the following code accomplishes that:

With rptMainInfo
  Set .DataSource = rsMainInfo
  .DataMember = rsMainInfo.DataMember
  DoEvents
    If PrintEm = True Then
        .PrintReport
    Else
        .Show vbModal
    End If

End With

If the print option is selected, the report is sent directly to the default printer without giving the user any chance to direct it elsewhere.  The user now wants the ability to decide which printer to send the hard copy output.  Showing them the standard windows printer selection box would be ideal if possible.  If not, are there other options?  Any ideas on how to accomplish this within the program flow?

I also have some output being generated by the Printform command.  Is there anyway to allow them to select where they want to direct that output?
0
Question by:mlcktmguy
    10 Comments
     
    LVL 48

    Expert Comment

    by:Mikal613
    you can add your own combo Box  and do this

    Private Sub LoadPrinters()

    Dim P as Printer

     For Each P In Printers
            CMB.Additem  P.DeviceName & " on " & P.Port =
      Next

    End sub

    0
     
    LVL 28

    Expert Comment

    by:vinnyd79
    Here is an example that uses a combobox:

    Private Sub Form_Load()
    LoadPrinters
    End Sub

    Private Sub Combo1_Click()
    Set Printer = Printers(Combo1.ListIndex)
    End Sub

    Private Sub LoadPrinters()
    Dim pr As Printer

    For Each pr In Printers
       Combo1.AddItem pr.DeviceName
    Next pr
    Combo1.Text = Printer.DeviceName

    End Sub
    0
     
    LVL 48

    Expert Comment

    by:Mikal613
    When you print  you then Set the printer to what he slelected


    dim P as printer
    For Each P In Printers
            If P.DeviceName & " on " & P.Port = cboPrinters.Text Then
                Set Printer = P
                Exit For
            End If
        Next
    0
     
    LVL 48

    Accepted Solution

    by:
    else

    add a Common Dialog

    and do showprinter
    0
     
    LVL 14

    Expert Comment

    by:Shiju Sasidharan
    hi
    try this
    '----------------------------------------
    With rptMainInfo
      Set .DataSource = rsMainInfo
      .DataMember = rsMainInfo.DataMember
      DoEvents
        If PrintEm = True Then
    '>> Change made here..

            .PrintReport True
        Else
            .Show vbModal
        End If

    End With
    '-----------------------------

    ;-)
    Shiju

    0
     
    LVL 1

    Author Comment

    by:mlcktmguy
    when I put in the command ShowPrinter I get a compile error.  The ShowPrinter command is highlighted and the message is:

    Sub or Function Not Defined

    0
     
    LVL 48

    Expert Comment

    by:Mikal613
    Did you add a Commn Dialog ??
    0
     
    LVL 48

    Expert Comment

    by:Mikal613
    CommonDialog Control
               

    The CommonDialog control provides a standard set of dialog boxes for operations such as opening and saving files, setting print options, and selecting colors and fonts. The control also has the ability to display help by running the Windows Help engine.

    Syntax

    CommonDialog

    Remarks

    The CommonDialog control provides an interface between Visual Basic and the routines in the Microsoft Windows dynamic-link library Commdlg.dll. To create a dialog box using this control, Commdlg.dll must be in your Microsoft Windows SYSTEM directory.

    You use the CommonDialog control in your application by adding it to a form and setting its properties. The dialog displayed by the control is determined by the methods of the control. Atrun time, a dialog box is displayed or the help engine is executed, when the appropriate method is invoked; atdesign time, the CommonDialog control is displayed as an icon on a form. This icon can't be sized.

    The CommonDialog control can display the following dialogs using the specified method.

    Method Dialog Displayed
    ShowOpen Show Open Dialog Box
    ShowSave Show Save As Dialog Box
    ShowColor Show Color Dialog Box
    ShowFont Show Font Dialog Box
    ShowPrinter Show Print or Print Options Dialog Box
    ShowHelp Invokes the Windows Help Engine


    0
     
    LVL 1

    Author Comment

    by:mlcktmguy
    Yes, that worked better than the combo box approach.  I'm not sure why?
    When I used the combo box I had 'stops' throughout the code to make sure that it was setting the printer properly based on what was selected.  It was, but when I printed the report it still went to the default printer.  I decided to try the common dialog box and it worked.  I still can't get the thing to print in landscape but I'll be posting another question on that.

    Thanks for your help
    0
     
    LVL 48

    Expert Comment

    by:Mikal613
    I have the answer 2 that too when your ready
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
    Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    856 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now