Link to home
Start Free TrialLog in
Avatar of SweetingA
SweetingA

asked on

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.
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
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
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.

Ron
Avatar of SweetingA
SweetingA

ASKER

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
        Me.TabCtl0.Pages(x).SetFocus
        DoCmd.PrintOut acPrintAll
    Next x
   
    Me.TabCtl0.Pages(0).SetFocus
    Me.FilterOn = False
   
Exit_PrintDocument_Click:
    Exit Sub

Err_PrintDocument_Click:
    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.