List box selection to a number of tboxes

dubiousp

New Member
Joined
Aug 12, 2015
Messages
32
Hello all,, please forgive me I posted a similar question a couple of days ago but did not explain very well

Im trying for our local charity to write a medic logging VBA Excel,, one of the user forms is to log up eight drugs (ufmedication) the form consists of a listbox (lbdrugs) sourced from a column list,, 8 text boxes (tbmed1 to tbmed) in addition there is a text box for searching (tbmedsearch)

My preferred operation was is that i would start to enter text into tbmed1 and then select from list to move to tbmed2 ect. If this was not possible going to use search box....

However I have two codes one that is the lbdugs look up and one that is the tb selection

this code seems to run then halts at tbmed2.value

Private Sub lbdrugs_*******()



ClearControls
If Me.lbdrugs.ListIndex = -1 Then 'not selected
'MsgBox " No selection made"
ElseIf Me.lbdrugs.ListIndex >= 1 Then 'User has selected
r = Me.lbdrugs.ListIndex
With Me
.tbmed1.Value = lbdrugs.List(r, 0)
'.tbmed2.SetFocus
.tbmed2.Value = lbdrugs.List(r, 1)

'etc
'End With
End If
End Sub


The below is my lbdrugs search code
Private Sub tbmedsearch_Change()






Dim i As Long
Dim sFind As String

sFind = Me.tbmedsearch.Text

If Len(sFind) = 0 Then
Me.lbdrugs.ListIndex = -1
Me.lbdrugs.TopIndex = 0
Else
For i = 0 To Me.lbdrugs.ListCount - 1
If UCase(Left(Me.lbdrugs.List(i), Len(sFind))) = UCase(sFind) Then
Me.lbdrugs.TopIndex = i
Me.lbdrugs.ListIndex = i

Exit For
End If
Next i
End If
End Sub
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

Forum statistics

Threads
1,223,889
Messages
6,175,224
Members
452,620
Latest member
dsubash

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