Also allow code to be run if user presses the ENTER button

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
Hi,
I am using the code below which will run on a click event.

I would also like to have it run should the user press the ENTER button on the keyboard.
Please advise thanks.

Rich (BB code):
Private Sub KnownInvoice_Click()
    Const FILE_PATH As String = "C:\Users\Ian\Desktop\REMOTES ETC\DR\DR COPY INVOICES\"
    
    If Len(Dir(FILE_PATH & OpenKnownInvNumber.Value & ".pdf")) = 0 Then
            If MsgBox("INVOIVR NUMBER NOT FOUND, OPEN FOLDER ?", vbCritical + vbYesNo, "INVOICE NUMBER NOT FOUND.") = vbYes Then
                CreateObject("Shell.Application").Open ("C:\Users\Ian\Desktop\REMOTES ETC\DR\DR COPY INVOICES\")
    End If
        Else
            CreateObject("Shell.Application").Open (FILE_PATH & OpenKnownInvNumber.Value & ".pdf")
            OpenKnownInvNumber.Value = ""
        End If

End Sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
What type is the control? Which will be the active control when you press Enter?
This can be initiated from any control on the form which can initiate KeyDown event.
Something like this adjusted to your form has to work:
VBA Code:
Private Sub TextBox2_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    If KeyCode = 13 And Shift = 0 Then Call KnownInvoice_Click
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,124
Messages
6,123,189
Members
449,090
Latest member
bes000

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top