Results 1 to 6 of 6

Thread: Resetting Default Printer in Code

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2005
    Posts
    32

    Resetting Default Printer in Code

    I am currently using VB6 with SP6 installed. I have the Component One add-on also installed. I am using the VSPRINT object to preview/print out a report. There are two basic types of printers that I use.

    The two types are:
    1 - 8 1/2 inch x 11 inch
    2 - 3 inch Receipt Continious

    I want to be able to set the default printer temporarily within code so that I can have the report program print to the appropriate printer needed by the specific report that is being requested.

    I have this code already there

    Public Function SetPrinter(ByVal DeviceName As String) As Boolean

    Dim X As Printer

    If Printers.Count > 0 Then
    For Each X In Printers
    MsgBox (X.DeviceName)
    If InStr(LCase(X.DeviceName), DeviceName) Then
    MsgBox ("Set " & X.DeviceName & " as default printer")
    Set Printer = X
    SetDefaultPrinter = True
    Exit For
    End If
    Next X
    End If
    End Function

    but even though it shows that the current device set is 8 1/2inch by 11 inch style printer when it goes to the preview it shows it as the default printer which in some cases is quite possible to be the 3inch receipt printer. Therefore if it is the 3inch style it does not display correctly and also when it is told to print it prints to the default printer even though the code above is set such that the default printer within the program should be the one with MAIN in its name which will be the 8 1/2 inch x 11 inch printer.

    ANy suggestions or ideas?

    Thanks in advance for your help in this.

    Seasons Greetings & God Bless to you and yours.

  2. #2

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2005
    Posts
    32

    Re: Resetting Default Printer in Code

    Thank you RhinoBull. I am now going to implement this into the code that I am currently working on. Seems that lots of folks are asking about changing the printer through code. Sorry that I seeem to be one of the many who ask. But I am sure very glad that you answered.

    Consider this resolved and again thanks for your time and help in this matter.

  4. #4
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Resetting Default Printer in Code

    Quote Originally Posted by DaWolf
    Consider this resolved and again thanks for your time and help in this matter.
    You're welcome. Also, since you "Consider this resolved" then you may "officially" do that by pulling down thread's menu ... Thanks.

  5. #5
    Hyperactive Member
    Join Date
    May 2006
    Location
    Gorgeous Ontario
    Posts
    265

    Re: Resetting Default Printer in Code

    Its a great solution if you want to enumerate the printers and display it the the user. If you simply just want to change default printers than all you need is this:
    VB Code:
    1. Option Explicit
    2. Private Declare Function SetDefaultPrinter Lib "winspool.drv" _
    3.    Alias "SetDefaultPrinterA" _
    4.   (ByVal pszPrinter As String) As Long
    5.  
    6. Private Sub Command1_Click()
    7.    SetDefaultPrinter "PrinterNameHere"
    8. End Sub

  6. #6
    Junior Member
    Join Date
    Aug 2015
    Posts
    27

    Re: Resetting Default Printer in Code

    Quote Originally Posted by Falconsbane View Post
    Its a great solution if you want to enumerate the printers and display it the the user. If you simply just want to change default printers than all you need is this:
    VB Code:
    1. Option Explicit
    2. Private Declare Function SetDefaultPrinter Lib "winspool.drv" _
    3.    Alias "SetDefaultPrinterA" _
    4.   (ByVal pszPrinter As String) As Long
    5.  
    6. Private Sub Command1_Click()
    7.    SetDefaultPrinter "PrinterNameHere"
    8. End Sub
    Dang Man you are truly Godsend been looking for this for days
    tnx alot man

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