View Single Post
 
Old 07-24-2023, 05:32 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,994
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

I'm going to assume you have a vba Userform which is where the ComboBox2 and Textbox1 objects are sitting. The code should be located in that object (the userform itself).

In that userform you will need two macros that autoexecute (run when events happen that align with the name of the macro). So add this code to the userform module.
Code:
Private Sub UserForm_Initialize()
  Dim depts() As String
  depts = Split("Accounting|Maintenance|Commissary|Sales|Field Reps", "|")
  Me.ComboBox2.List = depts
End Sub

Private Sub ComboBox2_Change()
  Dim people() As String
  people = Split("Mary Smith|Fred Jones|Jose Lima|Rick Nixon|Sandy Banning", "|")
  If ComboBox2.ListIndex = -1 Then
    Me.TextBox1 = ""
  Else
    Me.TextBox1 = people(ComboBox2.ListIndex)
  End If
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote