afh110
01-04-2010, 03:10 AM
Hi All,
Im still really new at this but i hope you guys can guide me in the write direction. Im bulding Forms in Access 2007 but I dont know how to associate to controls that are dependant on each other! I have two Combo boxes (Combo1 and Combo2) I want when the user selects a value from the dropdown of Combo1, the dropdown content of Combo2 is populated based on that selection. I figured i need a macro and have an After_Selection event to handle this task. Here is my code:
Dim db As DAO.database
Dim rs As DAO.recordset
Dim strResult As String
Dim strSQL As String
Dim temp As String
temp = Combo1.Value
If Combo1.Value = "BSC" Then
strSQL = "SELECT BSC_Def.Name FROM BSC_Def WHERE BSC_Def.Scope_Code='temp';"
Set db = CurrentDb
Set rs = db.OpenRecordset(strSQL)
strResult = rs ' Im not sure how recordsets are handled? (arry,string..?)
Else of Combo1.value="Initiative" then
temp = Combo1.Value
------etc
End If
Combo2.RowSource = rs
I think my primary issue is how to get Combo2 to take in the recordsets queried by the after_update even of Combo1. Do i use controlsource or rowsource? please help :)
Im still really new at this but i hope you guys can guide me in the write direction. Im bulding Forms in Access 2007 but I dont know how to associate to controls that are dependant on each other! I have two Combo boxes (Combo1 and Combo2) I want when the user selects a value from the dropdown of Combo1, the dropdown content of Combo2 is populated based on that selection. I figured i need a macro and have an After_Selection event to handle this task. Here is my code:
Dim db As DAO.database
Dim rs As DAO.recordset
Dim strResult As String
Dim strSQL As String
Dim temp As String
temp = Combo1.Value
If Combo1.Value = "BSC" Then
strSQL = "SELECT BSC_Def.Name FROM BSC_Def WHERE BSC_Def.Scope_Code='temp';"
Set db = CurrentDb
Set rs = db.OpenRecordset(strSQL)
strResult = rs ' Im not sure how recordsets are handled? (arry,string..?)
Else of Combo1.value="Initiative" then
temp = Combo1.Value
------etc
End If
Combo2.RowSource = rs
I think my primary issue is how to get Combo2 to take in the recordsets queried by the after_update even of Combo1. Do i use controlsource or rowsource? please help :)