View Single Post
  #2   Report Post  
Norman Jones
 
Posts: n/a
Default Update Text Box Value

Hi Alan,

'-----------------------------------
Maybe a simple question

Can anyone tell me how I go about updating other text boxes from an input
in
one text box ??

I have an emloyee number that links to personnel information about an
individual .. I would like to enter a pay number in one box ... click a
button and their name etc is presented in the other boxes ...

Can anyone enlighten me please

Many thanks

'------------------------------------

Assume that the employee data is held in a range which you have named
"Table". Assume that column 1 of the table holds the employee ID numbers;
column 2 holds employee data, say Name, column 3 gives the employee title,
and so on. Assume further that the first table row comprises a header row.

From the Control Toolbox add as many textboxes as you have columns of data
to be read,

Assume that these text boxes are named: TextBox1, TextBox2 ...TextBoxn.

Right-click the worksheet tab and paste the following code:

'====================
Private Sub ListBox1_GotFocus()
Dim rng As Range

Set rng = Range("Table").Columns(1).Cells
Set rng = rng.Offset(1).Resize(rng.Cells.Count - 1)

ListBox1.List() = rng.Value

End Sub
'<<====================

'====================
Private Sub ListBox1_Change()
Dim myval As Variant
Dim rng As Range

Set rng = Range("Table")

myval = ListBox1.Value

TextBox1.Value = Application.VLookup(myval, rng, 2, 0)
TextBox2.Value = Application.VLookup(myval, rng, 3, 0)
TextBox3.Value = Application.VLookup(myval, rng, 4, 0)

End Sub
'<<====================

Insert an additional line of code for each additional text box, using the
name of the additional text box and changing the penultimate VLookup
parameter to accord with the Table's required data column.

Alt-F11 to return to the worksheet. Exit from design mode, by clickimg the
Control Toolbox (top left) set square icon, close the Control ToolBox.

Now, selecting an id number from the list box will update each of the text
boxes with data relating to the relevant employee.

---
Regards,
Norman