Open user form upon enter key press

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,199
Office Version
  1. 2007
Platform
  1. Windows
Hi,
On my worksheet i have in column A customers names & in column P of that row is the receipt number for that customer.
What i would like to happen is when a certain customers name in cell A is selected when i press the enter key have it open my userform called Database & if possible to then take it one step further upon opening the userform have that customers records loaded.

I can assist further with info etc should you need any other input.

Thanks
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
It looks like the Worksheet object doesn't contain a KeyPress event handler. Have you considered using either the BeforeDoubleClick event or SelectionChange event handlers? Your userform could be shown when the target cells are either doubled clicked or selected, depending on your preference.
 
Upvote 0
Hi,
No i havent,could you advise regarding double click as i think that would suit this best.

That would open the form but what about the file for the customer that i double clicked on

Thanks
 
Upvote 0
Hi,
This works to open the userform.

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)Database.Show
End Sub
 
Upvote 0
You should set Cancel to True so that you don't enter the cell in edit mode after unloading your form...

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Cancel = True
    Database.Show
End Sub

To restrict it to Column A, try the following instead...

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Intersect(Me.Columns("A"), Target) Is Nothing Then Exit Sub
    Cancel = True
    Database.Show
End Sub
 
Upvote 0
Hi,
The code to restrict it to column A works great.

Do you know how i can then pull up that customers file when it opens.

Thanks
 
Upvote 0
Hi,
When i am on the userform i can click a button and it will look at the receipt/invoice number then show me the pdf for that customer.
The code is shown below.
Im not sure if the bones can be picked out of that if it helps so when i double click on a customer his record in the database is displayed "not to show me the pdf this time"



Code:
Private Sub OpenInvoice_Click()

    Const FILE_PATH As String = "C:\Users\Ian\Desktop\REMOTES ETC\DR COPY INVOICES\"
    
    If txtInvoiceNumber = "N/A" Or Len(txtInvoiceNumber) = 0 Then
                MsgBox "Invoice N/A For This Customer", vbExclamation, "N/A INVOICE NOTICE"
    Else
        If Len(Dir(FILE_PATH & txtInvoiceNumber.Value & ".pdf")) = 0 Then
            If MsgBox("Would You Like To Open The Folder ?", vbCritical + vbYesNo, "Warning Invoice is Missing.") = vbYes Then
                CreateObject("Shell.Application").Open ("C:\Users\Ian\Desktop\REMOTES ETC\DR COPY INVOICES\")
            End If
        Else
            CreateObject("Shell.Application").Open (FILE_PATH & txtInvoiceNumber.Value & ".pdf")
        End If
    End If
End Sub
 
Upvote 0
I would suggest that you start a new thread, and provide all of the relevant details so that someone can provide you with a possible solution.
 
Upvote 0
Since you haven't provided any details, I'll assume the following...

Code:
1) Column A contains the customer name, and Column B and Column C contain the corresponding data for the customer.

2) The data for the customer, located in Column A, B, and C, is to be loaded onto 3 textboxes on the userform.

[UserForm Code Module]

Code:
Option Explicit

Private m_ws As Worksheet
Private m_rw As Long

Sub LoadData(ByVal ws As Worksheet, ByVal rw As Long)
    Set m_ws = ws
    m_rw = rw
    Me.TextBox1.Value = m_ws.Range("A" & m_rw).Value
    Me.TextBox2.Value = m_ws.Range("B" & m_rw).Value
    Me.TextBox3.Value = m_ws.Range("C" & m_rw).Value
    With Me.TextBox1
        .SetFocus
        .SelStart = 0
        .SelLength = Len(.Value)
    End With
    Me.Show
End Sub

[Sheet Code Module]

Code:
Option Explicit

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Intersect(Range("A2", Cells(Rows.Count, "A").End(xlUp)), Target) Is Nothing Then Exit Sub
    Cancel = True
    Database.LoadData Me, Target.Row
End Sub

You will need to adapt the code to suit your requirements.
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,215
Members
448,554
Latest member
Gleisner2

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