View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Userform Name Search

Use a combobox instead of a textbox. Look at the match related properties.

--
Regards,
Tom Ogilvy

"Michael Vaughan" wrote in message
...
Hello Everyone,

Can somebody help me with this code that I messed up??? What I am trying

to
do is, I created a UserForm that has a TextBox and a SpinButton. I have a
sheet with a database in it that lists a club with Members Names,

Addresses,
and Phone No's. Now, the SpinButton portion of the code works, but what I
want to do with the TextBox is, I want to be able to type in a few letters
of the last name, and then it comes up with the name/address and so on

info
below where it shows it in the spinbutton. Here is the code that I have
now, can somebody fix the TextBox function for me so that I can type in a
partial name and have it displayed??? NOTE: The code for the TextBox
Change was originally setup for a ListBox, I have a spinbutton instead of

a
listbox.

Dim HelpTopic As Integer

Private Sub CancelButton_Click()
Unload Me
End Sub

Private Sub TextBox1_Change()
'the change event runs each time the user
'types into a text box
Dim s As String
Dim i As Integer
s = TextBox1.Text

'Note the use of the ListIndex property of the ListBox
'If the ListIndex is -1 means nothing selected
'If 0 means the first item selected
LabelName.Caption = -1
If TextBox1.Text = "" Then 'nothing typed
Exit Sub
End If
For i = 0 To LabelName.Caption - 1
'use the LIKE operator to compare
'convert both to Uppercase as well so case does not matter
If UCase(LabelName.Caption(i)) Like UCase(s & "*") Then
LabelName.Caption = i
Exit Sub: UpdateForm
End If
Next
End Sub


Private Sub UpdateForm()
HelpTopic = SpinButton1.Value
LabelName.Caption = Sheets("Members").Cells(HelpTopic, 1)
LabelAdd.Caption = Sheets("Members").Cells(HelpTopic, 2)
LabelHome.Caption = Sheets("Members").Cells(HelpTopic, 3)
LabelWork.Caption = Sheets("Members").Cells(HelpTopic, 4)
LabelCell.Caption = Sheets("Members").Cells(HelpTopic, 5)
LabelEmail.Caption = Sheets("Members").Cells(HelpTopic, 6)
Me.Caption = "Sky-Vu Flyers Membership Listing (Pilot " & HelpTopic

&
" of " & SpinButton1.Max & ")"
End Sub

Private Sub SpinButton1_Change()
HelpTopic = SpinButton1.Value
UpdateForm
End Sub

Private Sub UserForm_Initialize()
' On Error Resume Next
With SpinButton1
.Max =
Application.WorksheetFunction.CountA(Sheets("Membe rs").Range("A:A"))
.Min = 1
.Value = 1
End With
UpdateForm
End Sub


Thanks in adavance.... Michael