Solved

Set Default Printer Within Access 2007

Posted on 2009-04-10
9
2,796 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
 

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

708 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

15 Experts available now in Live!

Get 1:1 Help Now