Link to home
Start Free TrialLog in
Avatar of mindreader13
mindreader13

asked on

Ms access 97 change default printer using vba on Windows 7

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
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

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?
@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.
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
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
Avatar of mindreader13
mindreader13

ASKER

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.
SOLUTION
Avatar of Jim Dettman (EE MVE)
Jim Dettman (EE MVE)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
<<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.
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
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.
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
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
Seems can't get an answer
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.
@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.
Please ignore my RA - as Jim said, there's some good information here, and probably is worth PAQing.
<<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.
etsherman ID: 39839943
Jim Dettman ID: 39838728

Jim.