Solved

Set Default Printer Within Access 2007

Posted on 2009-04-10
9
2,821 Views
Last Modified: 2013-11-27
Hi
I've run into more problems with my Access 2007/Merge Mail (Word 2007) application - refer my previous question. Everything within the Access /Mail Merge is working fine however the users asked if they could set one of several printers as the default printer from Access 2007 so when they sent the merged document to the default printer it would send the document to the printer they had designated as the default printer. When the application is started it builds a local table (working fine) of the printers installed on their PC which I uses to populate a combo box to allow the user to select one of the available printer and set it as the default printer. Unfortunately when the mail merge is done and the document is sent to the default printer (we are now in Word 2007) it replies that there is a problem because basically there is no default printer. Checking the printers via Start>Printers  none of the printers has the tick against printer icon indicating which printer is the default printer. If I manually set the default printer (via Start>Printers) and do the mail merge again and not select a different printer then everything works fine. The code below is some code I took from the Access Help screen to test the set default option and is basically the code I use in my application - except for the fact that I supply a printer name rather than using index of the printer collection. I have executed this code changing the index number from 1 to 2 to 3 etc and it is displaying the correct printer name etc but checking the printer setting via Start>Printer after each execution the printer selected is not set as the dfault printer.
I have looked through the EE knowledge base but I can't get a resolution to my problem. Is there something wrong with my logic or is this an Access 2007 bug and if so is there a fix available.
Many Thanks in advance.
MLA
Function SetDefaultPrinterTest()
 
 Dim prtDefault As Printer
 
 Set Application.Printer = Application.Printers(0)
 
 Set prtDefault = Application.Printer
 
 With prtDefault
    MsgBox "Device name: " & .DeviceName & vbCr _
        & "Driver name: " & .DriverName & vbCr _
        & "Port: " & .Port
 End With

Open in new window

0
Comment
Question by:Adlerm
  • 4
  • 4
9 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 24114294
So from reading all that, you basically just want to set the default printer permanently? setting via applicaton.printer object works just for the duration of using that msaccess process.

You might be able to use wshnetwork
something like this

    Dim wsh As Object
    Set wsh = CreateObject("WScript.Network")

    wsh.SetDefaultPrinter("myprintername")
    Set wsh = Nothing
0
 

Author Comment

by:Adlerm
ID: 24120693
Hi rockiroads
Tried what you suggested but I get the following error

ActiveX component can't create object  - runtime error 429
Error occurs on  the Set wsh = CreateObject("Printername") line
I checked the References  - Microsoft ActiveX Data Objects (Multi Dimensional) 6.0 Library
                                              Microsoft Scripting Runtime
amoung others are checked.
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 24121153
urm, thinking you getting confused there

look at what I passed in CreateObject, not the printername but WScript.Network
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 

Author Comment

by:Adlerm
ID: 24124325
Hi rockiroads

My apologies - you are quite right. Unfortunately I made the mistake when replying. The error still stands however and it occurs on the  Set wsh = CreateObject("WScript.Network") line which I meant to say in my initial reply.
 
0
 
LVL 19

Assisted Solution

by:dlc110161
dlc110161 earned 25 total points
ID: 24132063
Did you happen to enable it through references? VBE, Tools, References?

Dawn Bleuel
Word MVP
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 24132662
if the object cant be created, it could be that you may not have windows scripting host installed.
0
 

Author Comment

by:Adlerm
ID: 24135185
Hi rockiroads/dlc110161:

Not sure what you mean by Windows Scripting Host - can it be set via References. As indicated earlier I have the following References checked
                                              Microsoft ActiveX Data Objects (Multi Dimensional) 6.0 Library
                                              Microsoft Scripting Runtime
Is there something else I need to check in the References? If so what is it called. The closest things I can see in the Reference list are

                                              Microsoft WMI Scripting V1.2 Library
                                              Windows Scrip Host Object  Model

I've checked both of these to see if they had any affect on the error I'm getting but the error still happens.

Cheers - MLA
0
 
LVL 65

Accepted Solution

by:
rockiroads earned 100 total points
ID: 24135225
Since we are creating objects, it is using late binding so there is no reason to add references. Now you have windows scripting installed by looking at the reference you specified so Im not sure why it is not picking it up.

Might as well try early binding now. If you just check Windows Script Host Object  Model, (dont need the other one), you can try this

    Dim wsh As New WshNetwork
   
    wsh.SetDefaultPrinter ("myprintername")
    Set wsh = Nothing


If this doesnt work, then Im thinking windows scripting host might need an update i.e. check for a later version.

0
 

Author Comment

by:Adlerm
ID: 24144001
Hi rockiroads

Still no go - now getting the following error
      " Compile error - User defined type not defined" on the   Dim wsh As New WshNetwork line. In fact the WshNetword is not offered as a vaild option when the intelli sense opens when typing.

Can I go back to square one. When I was testing my SetDefaultPrinter logic and then executing a GetDefaultPrinter module the GetDefaultPrinter code was returning the printer name I had selected in the SetDefaultPrinter logic (which gave the impression that the logic was working as expected).  However if I then looked at the printers via the Start>Printers path no printer was tagged as the default printer - that is no printer had the tick icon showing on the printer icon as happens when you manually set the default printer via Start>Printer>Right Click on the desired printer and selecting the Set As Default Printer from the sub menu options. I have assumed that the SetDefaultPrinter code would cause the selected default printer to have a tick against it as it does via the manual set default printer method. Is my thinking correct or am I totally mistaken. Does this indicate that my SetDefaultPrinter logic is only partially working.

Cheers MLA
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

825 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