I am new to access programming and I am currently having some difficulty with the recordset procedures. I'm not sure if I am doing right in opening the table and getting the data from it.

Any one can guide me on this so I could get rid of this stumbling block.

I have 3 combolist and what I am trying to do is when the user selects the 1st combolist, the 2nd combolist should show the list that belongs to that category.

Since I am not sure the process of connecting to the db, I'm not able to populate the list.

Appreciate if anyone could help me on this. Thank you


Dim strStudentName As String
Dim strCategory As String
Dim strCode As String
Dim strSQL As String
Dim db As Database
Dim rst As Recordset
Dim rstRecord As Recordset


Public Sub cboStudentName_AfterUpdate()

    strStudentName = cboStudentName.Value           'get value of 1st combo list
    cboCategory.Value = "Select Category"   'set 1st value of 2ndst combo list
    cboCode.Value = "Select Code"           'set 1st value of 3rd combo list
    
    Set db = CurrentDb() ' select DB
    Set rst = db.OpenRecordset("ComboBox_Category") 'open table in DB
     
    strSQL = "Select Distinct ComboBox_Category.Category " & _
        "FROM ComboBox_Category " & _
        "WHERE ComboBox_Category.StudentName = '" & strStudentName & "' " & _
        "ORDER BY ComboBox_Category.Category;"
     rstRecord = db.OpenRecordset(strSQL) 'get records of select query from the DB
     
     Do While Not rst.EOF
        MsgBox rstRecord 'print out the records in msg box but in actual fact i'm trying to add in the records into the combo list
        rst.MoveNext
    Loop
        
End Sub