Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
cvw cvw is offline
external usenet poster
 
Posts: 2
Default Excel macro or command button to search using a user form

I have a user form which shows info about each student. I want to be able to
enter a student's name in a textbox and have all the fields on the form
populated with the student information.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 489
Default Excel macro or command button to search using a user form

You need to be a lot more specific on what you are wanting else we have to
make a lot of assumptions.

I would recommend using a combobox instead of a textbox. This way you can
utilize the Change Event and have the students info. automatically filled in
the rest of your userform. I will assume you have a list of students in
Sheet1 in Col. A. Just set the RowSource property of the combobox to the
range of students, for example, Sheet1!A2:A100. Now I will assume the
students information is in Col. B thru Col. D. Use this code below. You
will have to tweak it to your application. It should get you started. Hope
this helps! If so, let me know, click "YES" below.

Private Sub ComboBox1_Change()

Dim Student As Range
Dim rw As Long

Set Student = Sheets("Sheet1").Range("A:A").Find(What:=ComboBox1 .Text, _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
MatchCase:=False)

If Not Student Is Nothing Then

rw = Student.Row
With Sheets("Sheet1")
Me.TextBox1 = .Cells(rw, "B").Value
Me.TextBox2 = .Cells(rw, "C").Value
Me.TextBox3 = .Cells(rw, "D").Value
'etc.
End With
Else
MsgBox "Student not found."
End If

End Sub

--
Cheers,
Ryan


"cvw" wrote:

I have a user form which shows info about each student. I want to be able to
enter a student's name in a textbox and have all the fields on the form
populated with the student information.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
macro attached to command button - VBA form Roy Gudgeon[_2_] Excel Discussion (Misc queries) 2 March 16th 10 12:44 PM
How to activate command button on form by macro Denis[_4_] Excel Programming 2 October 24th 08 08:59 PM
Accessing the text of a form command button from underlying macro Chrisso Excel Programming 6 September 15th 07 03:02 PM
User form and Command button Marilyn Excel Discussion (Misc queries) 3 May 9th 07 12:50 AM
Command Button on User form for Printing Anthony Slater Excel Discussion (Misc queries) 2 September 7th 05 02:01 PM


All times are GMT +1. The time now is 03:52 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"