Solved

Ms access 97 change default printer using vba on Windows 7

Posted on 2014-02-05
22
1,772 Views
Last Modified: 2014-05-17
I used to have some legacy MS Access 97 program that is running on Windows XP.  Currently, all workstations are using Windows 7 now and some of the code that used to change default printer of the OS doesn't work.  Pls check attached for that code.

I am now seeking for new MS Access 97 vba code that can change default printer on Windows 7.  Please help.
PrinterSet.txt
0
Comment
Question by:mindreader13
  • 6
  • 5
  • 4
  • +1
22 Comments
 
LVL 84
ID: 39835592
Define what you mean by "doesn't work".

Do you receive an error?

Does the code not work?

Does it print, but not to the correct printer?

Are the workstations still using Access 97?
0
 
LVL 57
ID: 39836026
@Scott,

 In looking at the code by Albert, it's relying on changing .ini files to change the default printer.   I'm sure with Win 7 ini files were shown the door.

 I have code here which changes the default printer, but it works through API's, and still works under Win 7.

  But both sets of code I have are copy righted.  One is ATTAC consulting's On The Fly printing (now defunked) and the other is from the Access Developers Handbook.

  I don't know of any other code floating around that's free, but it will need to be something that utilizes the API calls.

  Unfortunately, with A97 there's not a lot of options as there was no printer object back then.

 Of course his other choice is to run the software in XP mode under Windows 7.

Jim.
0
 
LVL 19

Expert Comment

by:Eric Sherman
ID: 39836753
Another option is to convert the '97 legacy app to Access 2003 where you can use the printer object.  I ran into this a while back with a client.  They wanted to keep upgrading the O/S on workstations to more advanced versions without upgrading the Access app.  There comes a point in time when something becomes outdated as in your '97 app and it is more trouble to keep it running using advanced O/S like Windows 7.

My suggestion is, if it is just that important to keep the app running in Access '97 then it will be equally important to keep the O/S in Windows XP in order to keep everything working.

This will work with Access 2003 and later versions ... Print the report to two different printers using the Printer Object.

Dim strPrinter1 as String
Dim strPrinter2 as String
Dim Prt as Printer

strPrinter1 = "HP LaserJet"
strPrinter2 = "Lexmark"

'This stores the current default printer so it can be reset once finished
Set prt = Application.Printer

Application.Printer = Application.Printers(strPrinter1)
'Print your report
DoCmd.OpenReport YourReportName

Application.Printer = Application.Printers(strPrinter2)
'Print your report
DoCmd.OpenReport YourReportName

'Reset your default printer back to the original default printer on the machine
Application.Printer = prt


ET
0
 
LVL 19

Expert Comment

by:Eric Sherman
ID: 39836786
Another consideration is to have your '97 application print the reports to the Preview screen then allow the user to File ----> Print on the Menu Bar allowing the user to open the printer dialog box to select which printer they want to print to.

ET
0
 

Author Comment

by:mindreader13
ID: 39837915
Try to give a bit more information to let everyone understand my problem.  My task of the code is to be able to change default printer to "pdf printer" so to generate pdf for ms access 97.  

Using the existing code, it can't change the default printer.  

Below are my feedback to the comment:
-I have tried compatibility mode but failed.
-there is no preview set up for user so user can't print and select printer by themselves.
-can't convert to access 2003 as many code need to be rewritten.

I am still seeking for help. thx for all the expert there.
0
 
LVL 57

Assisted Solution

by:Jim Dettman (Microsoft MVP/ EE MVE)
Jim Dettman (Microsoft MVP/ EE MVE) earned 250 total points
ID: 39838728
<<-I have tried compatibility mode but failed.>>

 I don't understand that.   When you run XP as a virtual OS under Windows 7, you are running XP and it's no different then what your doing now.

<<-can't convert to access 2003 as many code need to be rewritten.>>

  Not all that much and in regards to the printer, it's going to be re-written anyway even if you stick with A97.  There is simply no way the method your currently using will work in Win 7.

I hunted around and found an old MSKB article with code:

How To Set Which Printer Is the System Default Printer
http://support.microsoft.com/default.aspx?scid=kb;EN-US;266767

That uses the API approach.   But this was back in the Win 95 days,  so not sure if it will work under Win7 or not.  If memory serves, there was a change to the DEVMODE structure at some point.

It's going to be tough to find code to do this because VB6.0 had a printer object, and Access 2003 up had a printer object, which made all the prior methods obsolete.  No one bothered with them past that because they were so complex.

ATTAC consulting had the "On The Fly" product available for a number of years, but once the printer object was added to Access (and I believe they did most of the work for that), there was no more need for their product.  

Basically the same for the printer code published in many of the computer books, including the Access Developers Handbook published by Sybex.  Last edition to have the printer API code was for Access 2000.

 In short, your living too far in the past at this point and I would seriously consider leaving Access 97 behind.

 It's funny, we just had this conversation more or less in another thread, because ADP's have been removed from Access.  The discussion was basically how long can you live on an old product without getting caught?   OS incompatibility was one of the things brought up.

 If however you are determined to stick with A97 and the above code does not work, then I'm sure you can find some old postings that would have code that would.  It's just a matter of tracking it down.

Jim.
0
 
LVL 19

Accepted Solution

by:
Eric Sherman earned 250 total points
ID: 39839943
If you are going to stick with Access '97, either one of the following work arounds would take less than 1 hour to implement ...

1.) Create a copy of your current reports with a PDF notation in the name ... something like PDFReport1, PDFReport2, etc. etc.  In design mode, simply change the default printer of the PDF reports to your PDF Printer Driver.  Then call the PDF version of the report at print time.

DoCmd.OpenReport "PDFReport1", acViewNormal


2.) Open each report to Preview mode and enable the File ----> Print option on the Menu Bar in your Access '97 app.  This will open the print dialog box allowing the user to select a printer.

DoCmd.OpenReport "Report1", acViewPreview


ET
0
 
LVL 57
ID: 39840034
<<If you are going to stick with Access '97, either one of the following work arounds would take less than 1 hour to implement ...>>

 That's a great idea.  In fact I have one client with an app that uses this exact method to re-direct labels to specific bar code printers.

 There are a few downsides / things to watch out for:

1. You have multiple copies of the report and now need to maintain those.

2. Because you are printing to different print devicies, you can get different results.   You have to be extremely carefull that printer settings are all matched as well as the device drivers.

  Usually that's not a big problem, but it's something that easily can creep in.  With the client above, it took a while to figure out why the warehouse was complianing about labels looking messed up when on the screen in preview they looked fine.  Turned out it was a difference in drviers.  Another time is was the margin was off.

 So just be aware of that.

 Sounds like you have a solution though!

Jim.
0
 
LVL 19

Expert Comment

by:Eric Sherman
ID: 39840176
Yes Jim .... Thanks for mentioning that.  I have a client that did not want to upgrade a Access 2000 app which also did not have the printer object but wanted to print certain reports in PDF format.  I tested several methods and found it was just easier to create specific reports that were defaulted to the PDF Printer driver since these reports did not change.  At report printing time the app showed the user a little Report Destination Form with an Option Group control ....  Printer, Preview or PDF.  Printer and Preview called the regular report and PDF called the PDF version that was defaulted to the PDF Driver.

Other considerations with this method would be inside the PDF Printer settings such as ...

Do you want the PDF to Open automatically
Do you want to be prompted for the name or specify the name within the app

Just depends on how you want the user to interact with the PDF creation.

ET
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:mindreader13
ID: 39841088
Additional information on my case:
-Currently that program will pop out a selection box to allow user to choose export format: like xls, csv, pdf, xdw, etc... pdf and xdw are handled by changing default printer method.  -In addition, after export method confirmed, one of the system even will export 5 reports all at once with the same format.
-- I believe it will be easier to update the code to change the default printer and i am still looking forward to it.

Jim:
We already have a new system that replace this legacy access 97 system.  But user still sometimes need to retrieve old record and print it to pdf in the legacy system.
In our case, we have quite a lot of report (>20+) that were written in access 97. Therefore, from resource point of view, it may be too much in my case using things suggested.  But really appreciate your suggestion. It just may be difficult to get it to work in my case.

ET:
Please help to check additional comment.
0
 
LVL 19

Expert Comment

by:Eric Sherman
ID: 39841682
mindreader13 ...

You said <<<<We already have a new system that replace this legacy access 97 system.  But user still sometimes need to retrieve old record and print it to pdf in the legacy system.  In our case, we have quite a lot of report (>20+) that were written in access 97. Therefore, from resource point of view, it may be too much in my case using things suggested.>>>>

If this is a legacy Access 97 system and you already have a new system that replaced it then the reports in the legacy system will not be changing.  Therefore, even with 20+ reports it would still only take you about 1 hour to duplicate them and create a PDFReport1, etc, etc  that has been defaulted to your PDF Printer Driver.  Note, you have spent 2 days searching for some code that probably does not exist.   That method is solid and you will never have another problem with the legacy system as your workstation O/S changes.

ET
0
 

Author Comment

by:mindreader13
ID: 39845211
There are many functions will be used when execute the reports.  Not just adding pdf report and change the report name.   Also need to handle reference and function for each report too.   Hope someone can be able to get me default printer.   If noone can suggest me the code.  I will use et approach instead
0
 

Author Comment

by:mindreader13
ID: 40057032
Seems can't get an answer
0
 
LVL 84
ID: 40058654
If you "can't get an answer", then why did you accept a comment as your solution? In cases like this, you should just thank the Experts for their time and delete the question.
0
 
LVL 57
ID: 40058806
@mindreader,

<<We already have a new system that replace this legacy access 97 system.  But user still sometimes need to retrieve old record and print it to pdf in the legacy system.
In our case, we have quite a lot of report (>20+) that were written in access 97. Therefore, from resource point of view, it may be too much in my case using things suggested.  But really appreciate your suggestion. It just may be difficult to get it to work in my case.>>

 I think given everything that has been said, your best bet is to run Windows XP compatibility mode under Windows 7 on a machine.   Note that I'm not talking about compatibility settings for a program running under Windows 7, but running Windows XP as a virtual machine in Windows 7, then running the app in that.

I also believe that the code in the MSKB article I posted would not take a large effort to get it running under Windows 7.

@Scott,

  Even though there is no clear solution for mindreader, there are a number of good ideas here for dealing with printing under Access 97.   I'd really hate to see it deleted.  

Jim.
0
 
LVL 84
ID: 40064294
Please ignore my RA - as Jim said, there's some good information here, and probably is worth PAQing.
0
 
LVL 57
ID: 40064378
<<Please ignore my RA - as Jim said, there's some good information here, and probably is worth PAQing. >>

 I really hate to go against the norm with no specific solution, but all of the ideas presented here would work.   If I had time, I would take this and turn it into an article (which is really what should be done with it and let the question  get deleted as it should).

 I have a feeling though we'll be using this more then a few times in the coming years, so I'd like to see it stick around.

 If anyone else would like to turn this into an article, that would be great and then we could let this die.

Jim.
0
 
LVL 57
ID: 40072140
etsherman ID: 39839943
Jim Dettman ID: 39838728

Jim.
0
 
LVL 84
ID: 40072188
Agreed.
0

Featured Post

IT, Stop Being Called Into Every Meeting

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

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

706 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

19 Experts available now in Live!

Get 1:1 Help Now