hii.. hw can i build a form with two drop down lists( combo boxes type 0), one for students and the other for their study center code. when this form is loaded fill the lists from the arrays. if the user pulls down one of the list and clicks on a student the corresponding study center code is displayed in the text box of the other list?
thnx for rplyin..
The main part depends on the way you save the students and their corresponding study centers.
Your application needs to read in the data.
Furthermore during the _load event you need to fill the dropdown lists with all students (probably their names) and all possible study centers (you would have to loop thru your data the get all possivble centers).
When the user clicks on a student, use this click event to set the corresponding listindex of the study center dropdown.
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button Wait, I'm too old to hurry!
This does what you're looking for. Place code in a form with two combo boxes (combo1 & combo2). It populates the arrays itself which you will probably want to change. It asumes an Integer value for the codes and links the student combobox (combo1) with the codes using the ItemData property.
Let me know if this helps..
Code:
'Arrays for storing student names and codes
Private students(0 To 4) As String
Private codes(0 To 4) As Integer
'Match the selected student's itemdata with that of the codes' and select the correct one
Private Sub Combo1_Click()
Dim Code As Integer
Dim i As Long
Code = Combo1.ItemData(Combo1.ListIndex)
For i = 0 To Combo2.ListCount - 1
If Combo2.ItemData(i) = Code Then
Combo2.ListIndex = i
Exit For
End If
Next
End Sub
'Fill arrays and dropdowns
Private Sub Form_Load()
FillArrays
FillDropDowns
End Sub
'Populate the arrays with students Mike1, Mike2 etc and corresponding codes 1111,1112 etc
Private Sub FillArrays()
students(0) = "Mike"
students(1) = "John"
students(2) = "Judie"
students(3) = "Sue"
students(4) = "Fred"
codes(0) = 1 'Mike's code
codes(1) = 2 'John's code
codes(2) = 3 'Judie's code
codes(3) = 4 'Sue's code
codes(4) = 5 'Fred's code
End Sub
'Populate the comboboxes and link combo1 to cmobo2 using the Integer code value as the itemdata of the associated student
Private Sub FillDropDowns()
Dim i As Long
For i = 0 To UBound(students)
Combo1.AddItem students(i)
Combo1.ItemData(Combo1.NewIndex) = codes(i)
Combo2.AddItem codes(i)
Combo2.ItemData(Combo2.NewIndex) = i
Next
End Sub
This does what you're looking for. Place code in a form with two combo boxes (combo1 & combo2). It populates the arrays itself which you will probably want to change. It asumes an Integer value for the codes and links the student combobox (combo1) with the codes using the ItemData property.
Let me know if this helps..
Code:
'Arrays for storing student names and codes
Private students(0 To 4) As String
Private codes(0 To 4) As Integer
'Match the selected student's itemdata with that of the codes' and select the correct one
Private Sub Combo1_Click()
Dim Code As Integer
Dim i As Long
Code = Combo1.ItemData(Combo1.ListIndex)
For i = 0 To Combo2.ListCount - 1
If Combo2.ItemData(i) = Code Then
Combo2.ListIndex = i
Exit For
End If
Next
End Sub
'Fill arrays and dropdowns
Private Sub Form_Load()
FillArrays
FillDropDowns
End Sub
'Populate the arrays with students Mike1, Mike2 etc and corresponding codes 1111,1112 etc
Private Sub FillArrays()
students(0) = "Mike"
students(1) = "John"
students(2) = "Judie"
students(3) = "Sue"
students(4) = "Fred"
codes(0) = 1 'Mike's code
codes(1) = 2 'John's code
codes(2) = 3 'Judie's code
codes(3) = 4 'Sue's code
codes(4) = 5 'Fred's code
End Sub
'Populate the comboboxes and link combo1 to cmobo2 using the Integer code value as the itemdata of the associated student
Private Sub FillDropDowns()
Dim i As Long
For i = 0 To UBound(students)
Combo1.AddItem students(i)
Combo1.ItemData(Combo1.NewIndex) = codes(i)
Combo2.AddItem codes(i)
Combo2.ItemData(Combo2.NewIndex) = i
Next
End Sub
.
thnx for the rply but m unable to use that code.. error
[highlight = vb]
actually i m beginner. so will u plz tell how to write the code in a step wise manner so that i can write it n run it correctly
[/highlight]
Referring to your problem to connect the the drop down lists:
What else do you need?
Jimbo Jnr did give you all the code needed, as well he stated which controls you need to add to your application. This code should run!
Referring to your problem to read the student and code data from a non specified storage place (textfile or database) you should search this forum!
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button Wait, I'm too old to hurry!
here is what u r lookin for man
download it from the attachment and code goes here too.
Code:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const CB_SHOWDROPDOWN = &H14F
'Written by Gaurav_Raj420
Private Sub Command1_Click()
On Error GoTo handler
Dim sStr As String
Dim Stud As Integer
Dim ComItm() As String
Dim Lup As Integer
Stud = InputBox("How Much Students ?", "Students")
ReDim ComItm(Stud)
For Lup = LBound(ComItm) To UBound(ComItm)
sStr = InputBox("Enter " & Lup & " Name")
Combo1.AddItem sStr
Next
MsgBox "Students Entries Have Been Added " & vbCrLf & "See them now", vbExclamation, "Students Entries"
SendMessage Combo1.hwnd, CB_SHOWDROPDOWN, 1, 1
Exit Sub
handler:
MsgBox Err.Description & vbNewLine & Err.Number, vbCritical, "Error"
End Sub
Private Sub Command2_Click()
On Error GoTo handler
Dim sStr As String
Dim StudyCntr As Integer
Dim ComItm() As String
Dim Lup As Integer
StudyCntr = InputBox("How Much Study Centers ?", "Study Center")
ReDim ComItm(StudyCntr)
For Lup = LBound(ComItm) To UBound(ComItm)
sStr = InputBox("Enter " & Lup & " Name")
Combo2.AddItem sStr
Next
MsgBox "Study Center's Entries Have Been Added " & vbCrLf & "See them now", vbExclamation, "Study Center Entries"
SendMessage Combo2.hwnd, CB_SHOWDROPDOWN, 1, 1
Exit Sub
handler:
MsgBox Err.Description & vbNewLine & Err.Number, vbCritical, "Error"
End Sub
Private Sub Command3_Click()
On Error GoTo handler
Dim Srch As Integer
Srch = InputBox("Enter Value To Search", "Search")
MsgBox "Name = " & Combo1.List(Srch) & " Education Center = " & Combo2.List(Srch)
Exit Sub
handler:
MsgBox Err.Description & vbNewLine & Err.Number, vbCritical, "Error"
End Sub
Private Sub Form_Load()
Combo1.Text = ""
Combo2.Text = ""
Label1.Caption = "Students"
Label2.Caption = "Study Centers"
Command1.Caption = "E&nter Students Name"
Command2.Caption = "&Enter Study Center"
Command3.Caption = "&Search"
Command1.Width = 2100
Command2.Width = 2100
Me.Width = 7000
End Sub
i know the topic is already [resolved] but i want to make this post because i made this prog for u adad..
Last edited by gaurav_raj420; Mar 30th, 2007 at 05:39 AM.
Reason: Tag-
Please keep away yourself from smoking
______________________
If you can't explain then don't write the hint because hint is always before when u have a problem. Okay?