tpoynton
01-10-2009, 12:24 PM
Greetings - had a tough time with the name of the thread...
I'm trying to clean up my code, and I have this little bit of code currently on a bunch of different userforms. I thought I'd put the code into a module, and just call the sub from each userform. It is harder than I thought (for me), as I have not found a way to make it work.
here is the code on the userform to call the code:
Call FindName(Me.TextBox_FindName, Me.ListBox_Name)
here is the code in the module. doesnt work; I've tried some variations of variables to get the name of the userform from the (string, userform, in addition to those listed), but can not seem to work it out.
Public Sub FindName(sCallingTbox As TextBox, sCallingLbox As ListBox)
'this is a psuedo autocomplete function
Dim txt As String
Dim i As Long
txt = sCallingTbox.Value & "*"
With sCallingLbox 'used to deal with multiselect being on
For i = 0 To .ListCount - 1
.Selected(i) = False
Next i
For i = 0 To .ListCount - 1
If txt <> "*" Then
If .List(i) Like txt Then
.Selected(i) = True
Exit For
End If
End If
Next i
End With
End Sub
I'm pretty sure there is something simple I am overlooking, but I have not been able to figure this out for a while!
Thanks, tim
I'm trying to clean up my code, and I have this little bit of code currently on a bunch of different userforms. I thought I'd put the code into a module, and just call the sub from each userform. It is harder than I thought (for me), as I have not found a way to make it work.
here is the code on the userform to call the code:
Call FindName(Me.TextBox_FindName, Me.ListBox_Name)
here is the code in the module. doesnt work; I've tried some variations of variables to get the name of the userform from the (string, userform, in addition to those listed), but can not seem to work it out.
Public Sub FindName(sCallingTbox As TextBox, sCallingLbox As ListBox)
'this is a psuedo autocomplete function
Dim txt As String
Dim i As Long
txt = sCallingTbox.Value & "*"
With sCallingLbox 'used to deal with multiselect being on
For i = 0 To .ListCount - 1
.Selected(i) = False
Next i
For i = 0 To .ListCount - 1
If txt <> "*" Then
If .List(i) Like txt Then
.Selected(i) = True
Exit For
End If
End If
Next i
End With
End Sub
I'm pretty sure there is something simple I am overlooking, but I have not been able to figure this out for a while!
Thanks, tim