• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 362
  • Last Modified:

Sending Keyboard Commands in Access VBA

I would like to send the equivelant of Ctrl+P in an on click event.

I am sure its simple but i cant find the correct codes.

all help most welocmes.
  • 2
1 Solution
Rey Obrero (Capricorn1)Commented:

You can use:
DoCmd.RunCommand acCmdPrint
However, don't you think it would be much better to create a dedicated report and adding a print button on a form to print this report.  Not only would the report be more professional looking, you would also use less toner/ink since you would avoid printing the GUI each time.

SweetingAAuthor Commented:
I have done that but i want to always select the windows default printer but my code does not work.  It knows what the printer is but never assigns it, it just keeps defaulting to the one which was set as the default in the form (a pdf printer).  I will paste the code i use below....

I thought sending cntl+p would at least allow the user to pick the printer.

Private Sub PrintDocument_Click()

On Error GoTo Err_PrintDocument_Click

Me.Dirty = False

Dim prt As Printer
Set Application.Printer = Nothing
Set prt = Application.Printer
Debug.Print "Current default printer: " & prt.DeviceName

    Dim s As Long
        s = Me.[Our Ref]
        Me.Filter = "[Our Ref]=" & s
        Me.FilterOn = True
    Dim x As Integer
    x = 0
    For x = 0 To 2
        DoCmd.PrintOut acPrintAll
    Next x
    Me.FilterOn = False
    Exit Sub

    MsgBox Err.Description
    Resume Exit_PrintDocument_Click
End Sub
If your report is set to go to a specific printer, then just go into the design mode of the report , select the Page Setup tab on the ribbon, then select the Page Setup icon, then the Page tab in the dialog box, and choose Default Printer.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now