populate cbo box with sql based on option selected

S

Song Su

I have a form with option group named fraHistory and unbound combo box
called cboYYYYS

If user select option1 in fraHistory, I want to populate combo box with
following SQL

SELECT DISTINCT [YYYY] & [SEM] AS Expr1
FROM Census
ORDER BY [YYYY] & [SEM] DESC;

If user select option2 in fraHistory, I want to populate combo box with:

SELECT DISTINCT [YYYY] & [SEM] AS Expr1
FROM Final
ORDER BY [YYYY] & [SEM] DESC;

What event should trigger this? How to code this unbound combo box?

Thanks.
 
K

Klatuu

Use the After Update event of the option group:

Dim strSQL As String

If Me.fraHistory = 1 Then
strSQL = "SELECT DISTINCT [YYYY] & [SEM] AS Expr1 FROM Census ORDER
BY [YYYY] & [SEM] DESC;"
Else
strSQL = "SELECT DISTINCT [YYYY] & [SEM] AS Expr1 FROM Final ORDER
BY [YYYY] & [SEM] DESC;"
End If

Me.MyCombo.RowSource = strSQL
 
Top