Using ASSESS 2010 and Windows 7.
Have a simple app that normally prints to the default printer. However, I have one button that that scans a plastic card, and I want the result to print to a small receipt printer, then rest the app back to the default (regular printer). I have tried a at least a dozen solutions from the web, none of which work. This seems simple enough, but getting it to work is a nightmare. Here is one example that I have tried, modified, and tried again and again, to no avail. I think I found on this site but not sure since I can't find it again. Here si the complete post.
---------------------------------------------------------------------------------
Yeah, you can write code that enumerates the Printers collection, locates a printer by name (or whatever), and sets this printer as the default printer for Access.
So you can write a function that returns a printer ...
Code:
Function GetPrinter(Name as string) As Access.Printer
dim prt as printer
for each prt in application.printers
if instr(prt.name, Name) then
set GetPrinter = prt
exit function
end if
next
err.raise -1, "GetPrinter()", "Printer not found"
end function
And you can, before you print a report, change the printer ...
Code:
dim prt as printer
set prt = application.printer
set application.printer = GetPrinter("YourNonDefaultPrinterNameHere")
'docmd.openreport "SomeReport"
set application.printer = prt
------------------------------------------------------------------------------
it always fails on this: set application.printer = GetPrinter("YourNonDefaultPrinterNameHere")
Error msg "Expected variable or procedure, not Module"
I put in a proper printer name, that I got from the printer collection.
Also I can never set the application.Printer to anything, examp.
Set Application.Printer ="Fax"
This all very confusing, so any light shed on the problem would really be appreciated.
BTW more than one person has told to just let the user select the printer because this is a real PITA. I don't accept that.
Thanks in advance
jpl
Have a simple app that normally prints to the default printer. However, I have one button that that scans a plastic card, and I want the result to print to a small receipt printer, then rest the app back to the default (regular printer). I have tried a at least a dozen solutions from the web, none of which work. This seems simple enough, but getting it to work is a nightmare. Here is one example that I have tried, modified, and tried again and again, to no avail. I think I found on this site but not sure since I can't find it again. Here si the complete post.
---------------------------------------------------------------------------------
Yeah, you can write code that enumerates the Printers collection, locates a printer by name (or whatever), and sets this printer as the default printer for Access.
So you can write a function that returns a printer ...
Code:
Function GetPrinter(Name as string) As Access.Printer
dim prt as printer
for each prt in application.printers
if instr(prt.name, Name) then
set GetPrinter = prt
exit function
end if
next
err.raise -1, "GetPrinter()", "Printer not found"
end function
And you can, before you print a report, change the printer ...
Code:
dim prt as printer
set prt = application.printer
set application.printer = GetPrinter("YourNonDefaultPrinterNameHere")
'docmd.openreport "SomeReport"
set application.printer = prt
------------------------------------------------------------------------------
it always fails on this: set application.printer = GetPrinter("YourNonDefaultPrinterNameHere")
Error msg "Expected variable or procedure, not Module"
I put in a proper printer name, that I got from the printer collection.
Also I can never set the application.Printer to anything, examp.
Set Application.Printer ="Fax"
This all very confusing, so any light shed on the problem would really be appreciated.
BTW more than one person has told to just let the user select the printer because this is a real PITA. I don't accept that.
Thanks in advance
jpl