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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top