If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Print dialog box how can I put it in with the following code:
I have the following code that I use to print a report:
Private Sub cmdPrintEmpNum_Click() On Error GoTo Err_cmdPrintEmpNum_Click Dim stDocName As String stDocName = "rptEmpNum" DoCmd.OpenReport "rptEmpNum", acNormal, , "[EmployeeNumber]=" & Me.cboEmployeeNumber Exit_cmdPrintEmpNum_Click: Me.cboEmployeeNumber = Null Exit Sub Err_cmdPrintEmpNum_Click: MsgBox Err.Description Resume Exit_cmdPrintEmpNum_Click End Sub I want to add the print dialog box so the end user can pick what printer they want to print to. I have tried to insert the following code in numerous places with out success: DoCmd.RunCommand acCmdPrint Can someone help me on what I need to change so the end user can have a print dialog box! Thanks R~ |
#2
|
|||
|
|||
Print dialog box how can I put it in with the following code:
IF you going to give a user the options to setup the printer (select which
printer), then you simply just need to display the report first.... If you really really want to nag the person each time, and make them not like you, and require a room with padded walls, then after you launch the reprot in preview mode, then you can execute the You can use: On Error Resume Next DoCmd.SelectObject acReport, Screen.ActiveReport.Name DoCmd.RunCommand acCmdPrint The select object command is needed to fix a "focus" bug if you have a form with a timer function. IF not, then your use of DoCmd.RunCommand acCmdPrint Should do the trick, but you have to open your reprot with acViewPreview eg: stDocName = "rptEmpNum" DoCmd.OpenReport stDocName,acViewPreview, , _ "[EmployeeNumber] = " & Me.cboEmployeeNumber DoCmd.RunCommand acCmdPrint -- Albert D. Kallal (Access MVP) Edmonton, Alberta Canada http://www.members.shaw.ca/AlbertKallal |
#3
|
|||
|
|||
Print dialog box how can I put it in with the following code:
Albert..
I read and did what you suggested.. works great... One more question.. How can I have it so they don't even see the report.. they just get the print dialog box? The reason is because the some of the bosses want the reports printed on their printers via the network.. that is why I want to give them the choice as to where to print it ever time... Thanks R~ "Albert D.Kallal" wrote: IF you going to give a user the options to setup the printer (select which printer), then you simply just need to display the report first.... If you really really want to nag the person each time, and make them not like you, and require a room with padded walls, then after you launch the reprot in preview mode, then you can execute the You can use: On Error Resume Next DoCmd.SelectObject acReport, Screen.ActiveReport.Name DoCmd.RunCommand acCmdPrint The select object command is needed to fix a "focus" bug if you have a form with a timer function. IF not, then your use of DoCmd.RunCommand acCmdPrint Should do the trick, but you have to open your reprot with acViewPreview eg: stDocName = "rptEmpNum" DoCmd.OpenReport stDocName,acViewPreview, , _ "[EmployeeNumber] = " & Me.cboEmployeeNumber DoCmd.RunCommand acCmdPrint -- Albert D. Kallal (Access MVP) Edmonton, Alberta Canada http://www.members.shaw.ca/AlbertKallal |
#4
|
|||
|
|||
Print dialog box how can I put it in with the following code:
How can I have it so they don't even see the report.. they just get the
print dialog box? The reason is because the some of the bosses want the reports printed on their printers via the network.. that is why I want to give them the choice as to where to print it ever time... Ok, you certainly made a good case/point for the dialog box each time..... What you can do is display the dialog..and then CLOSE the report for them eg: strReport = "altry" DoCmd.OpenReport strReport, acViewPreview DoCmd.RunCommand acCmdPrint DoCmd.Close acReport, strReport In the above, users would see the reprot, but least they would not have to close it (so, not such a big deal that they sort of see the reprot...since it would close for them...exaclty the SAME number of mouse clicks if they could not see the reprot anyway - so, not a big deal). however, you REALLY must select the printer, and REALLY don't want users to see the report, then the next solution would require code to get/save the current printer (default). Switch the users default to the printer of choice....and then print...and then switch the default printer back to the previous default... You don't mention what version\ of ms-access. In access 2002 and later, there is a built in printer object, and it lets you switch the printer with ease. You can use: Set Application.Printer = Application.Printers("HP LaserJet Series II") So, to save/switch, you can use: dim strDefaultPrinter as string ' get current default printer. strDefaultPrinter = Application.Printer.DeviceName ' switch to printer of your choice: Set Application.Printer = Application.Printers("HP LaserJet Series II") do whatever. Swtich back. Set Application.Printer = Application.Printers(strDefaultPrinter) This would mean that we build our own printer dialog form that lets the user select what printer. You could write code to iterate the printers collection, and fill up a listbox, or combo box.... -- Albert D. Kallal (Access MVP) Edmonton, Alberta Canada http://www.members.shaw.ca/AlbertKallal |
#5
|
|||
|
|||
Print dialog box how can I put it in with the following code:
Albert..
Thanks a ton... I will stick to the first one, it isn't a big deal that they see it, but I wanted it to close. Cuts down on the mouse clicks.. LOL.. and also thank you for the other suggestion. I am cutting and coping it for future use!! Thanks again for your help! R~ "Albert D.Kallal" wrote: How can I have it so they don't even see the report.. they just get the print dialog box? The reason is because the some of the bosses want the reports printed on their printers via the network.. that is why I want to give them the choice as to where to print it ever time... Ok, you certainly made a good case/point for the dialog box each time..... What you can do is display the dialog..and then CLOSE the report for them eg: strReport = "altry" DoCmd.OpenReport strReport, acViewPreview DoCmd.RunCommand acCmdPrint DoCmd.Close acReport, strReport In the above, users would see the reprot, but least they would not have to close it (so, not such a big deal that they sort of see the reprot...since it would close for them...exaclty the SAME number of mouse clicks if they could not see the reprot anyway - so, not a big deal). however, you REALLY must select the printer, and REALLY don't want users to see the report, then the next solution would require code to get/save the current printer (default). Switch the users default to the printer of choice....and then print...and then switch the default printer back to the previous default... You don't mention what version\ of ms-access. In access 2002 and later, there is a built in printer object, and it lets you switch the printer with ease. You can use: Set Application.Printer = Application.Printers("HP LaserJet Series II") So, to save/switch, you can use: dim strDefaultPrinter as string ' get current default printer. strDefaultPrinter = Application.Printer.DeviceName ' switch to printer of your choice: Set Application.Printer = Application.Printers("HP LaserJet Series II") do whatever. Swtich back. Set Application.Printer = Application.Printers(strDefaultPrinter) This would mean that we build our own printer dialog form that lets the user select what printer. You could write code to iterate the printers collection, and fill up a listbox, or combo box.... -- Albert D. Kallal (Access MVP) Edmonton, Alberta Canada http://www.members.shaw.ca/AlbertKallal |
#6
|
|||
|
|||
Print dialog box how can I put it in with the following code:
Hi again..
I did the code you said and the report is still remaining open. Here is the code: strReport = "altry" stDocName = "rptEmpNum" DoCmd.OpenReport stDocName, acViewPreview, , "[EmployeeNumber]=" & Me.cboEmployeeNumber DoCmd.RunCommand acCmdPrint DoCmd.Close acReport, strReport Exit_cmdPrintEmpNum_Click: Me.cboEmployeeNumber = Null R~ "Rhett_Y" wrote: Albert.. Thanks a ton... I will stick to the first one, it isn't a big deal that they see it, but I wanted it to close. Cuts down on the mouse clicks.. LOL.. and also thank you for the other suggestion. I am cutting and coping it for future use!! Thanks again for your help! R~ "Albert D.Kallal" wrote: How can I have it so they don't even see the report.. they just get the print dialog box? The reason is because the some of the bosses want the reports printed on their printers via the network.. that is why I want to give them the choice as to where to print it ever time... Ok, you certainly made a good case/point for the dialog box each time..... What you can do is display the dialog..and then CLOSE the report for them eg: strReport = "altry" DoCmd.OpenReport strReport, acViewPreview DoCmd.RunCommand acCmdPrint DoCmd.Close acReport, strReport In the above, users would see the reprot, but least they would not have to close it (so, not such a big deal that they sort of see the reprot...since it would close for them...exaclty the SAME number of mouse clicks if they could not see the reprot anyway - so, not a big deal). however, you REALLY must select the printer, and REALLY don't want users to see the report, then the next solution would require code to get/save the current printer (default). Switch the users default to the printer of choice....and then print...and then switch the default printer back to the previous default... You don't mention what version\ of ms-access. In access 2002 and later, there is a built in printer object, and it lets you switch the printer with ease. You can use: Set Application.Printer = Application.Printers("HP LaserJet Series II") So, to save/switch, you can use: dim strDefaultPrinter as string ' get current default printer. strDefaultPrinter = Application.Printer.DeviceName ' switch to printer of your choice: Set Application.Printer = Application.Printers("HP LaserJet Series II") do whatever. Swtich back. Set Application.Printer = Application.Printers(strDefaultPrinter) This would mean that we build our own printer dialog form that lets the user select what printer. You could write code to iterate the printers collection, and fill up a listbox, or combo box.... -- Albert D. Kallal (Access MVP) Edmonton, Alberta Canada http://www.members.shaw.ca/AlbertKallal |
#7
|
|||
|
|||
Print dialog box how can I put it in with the following code:
Nevermind I figured it out...
Thanks a bunch!!!! Works like a charm!!!!!! R~ "Rhett_Y" wrote: Albert.. Thanks a ton... I will stick to the first one, it isn't a big deal that they see it, but I wanted it to close. Cuts down on the mouse clicks.. LOL.. and also thank you for the other suggestion. I am cutting and coping it for future use!! Thanks again for your help! R~ "Albert D.Kallal" wrote: How can I have it so they don't even see the report.. they just get the print dialog box? The reason is because the some of the bosses want the reports printed on their printers via the network.. that is why I want to give them the choice as to where to print it ever time... Ok, you certainly made a good case/point for the dialog box each time..... What you can do is display the dialog..and then CLOSE the report for them eg: strReport = "altry" DoCmd.OpenReport strReport, acViewPreview DoCmd.RunCommand acCmdPrint DoCmd.Close acReport, strReport In the above, users would see the reprot, but least they would not have to close it (so, not such a big deal that they sort of see the reprot...since it would close for them...exaclty the SAME number of mouse clicks if they could not see the reprot anyway - so, not a big deal). however, you REALLY must select the printer, and REALLY don't want users to see the report, then the next solution would require code to get/save the current printer (default). Switch the users default to the printer of choice....and then print...and then switch the default printer back to the previous default... You don't mention what version\ of ms-access. In access 2002 and later, there is a built in printer object, and it lets you switch the printer with ease. You can use: Set Application.Printer = Application.Printers("HP LaserJet Series II") So, to save/switch, you can use: dim strDefaultPrinter as string ' get current default printer. strDefaultPrinter = Application.Printer.DeviceName ' switch to printer of your choice: Set Application.Printer = Application.Printers("HP LaserJet Series II") do whatever. Swtich back. Set Application.Printer = Application.Printers(strDefaultPrinter) This would mean that we build our own printer dialog form that lets the user select what printer. You could write code to iterate the printers collection, and fill up a listbox, or combo box.... -- Albert D. Kallal (Access MVP) Edmonton, Alberta Canada http://www.members.shaw.ca/AlbertKallal |
Thread Tools | |
Display Modes | |
|
|