Solved

Need to enter 2 initials in a Combo box to populate User form

Posted on 2015-02-10
5
58 Views
Last Modified: 2015-02-10
I am using this code to auto populate a user form.  I only takes one initial before it auto pops the form.  I would like to enter both as I have several employees with the same first initial

Private Sub ComboBox1_Change() 'auto pop by initials
Dim idx As Long

    idx = ComboBox1.ListIndex

    If idx <> -1 Then

        With Sheets("EmployeeName")
            TxtFname.Value = .Range("B" & idx + 2).Value 'fname
           
            TxtLName.Value = .Range("C" & idx + 2).Value 'lastname
           
            TxtStatus.Value = .Range("F" & idx + 2).Value 'status
           
            TxtHDept.Value = .Range("D" & idx + 2).Value 'HDept
           
            TxtUPH.Value = .Range("G" & idx + 2).Value 'UPH
           
      End With
       
    End If

    'new
    CB2FunctionCode.SetFocus
   
End Sub
0
Comment
Question by:bjfulkerson
  • 3
  • 2
5 Comments
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40601094
Your code should be in the Click event rather than the Change event. That way it will execute when the user makes his selection.
0
 

Author Comment

by:bjfulkerson
ID: 40601116
Click event for Combo Box 1?
0
 
LVL 45

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 40601214
Yes.

If that doesn't work then please attach your workbook, or an obfuscated one if the data is sensitive.
0
 

Author Closing Comment

by:bjfulkerson
ID: 40601398
Martin,
You have been very helpful!

Cheers,
Jody
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40601413
You're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2014
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now