# Database Discussions > Microsoft Access >  SELECT TOP x - MS Access SQL Query problem

## marklord

I have a database of questions which I use for a local quiz league and want to be able to produce random questions based on category and difficulty.  I currently have the following query: - 

SELECT TOP 10 Questions.*, Questions.Difficulty, Questions.[Main Category], Questions.[Specialist Category]
FROM Questions
WHERE (((Questions.Difficulty)=Forms![Random Questions]!DifficultyRating) And ((Questions.[Main Category])=Forms![Random Questions]![Main Category])) Or (((Questions.[Specialist Category])=Forms![Random Questions]![Specialist Category]))
ORDER BY Rnd([Question ID]);

Which generates 10 random questions based on the restrictions mentioned, however I want to be able to make the number of questions a variable chosen from a combo box or text box on a form.  Is this possible and easily integrated into this query and if so, how?


If anyone could help, it would be greatly appreciated, my email address for correspondance is marklord82@hotmail.com

Cheers,

Mark

----------


## Dan Hangen

Hey Mark,

This is a vb script I used to select a State from a combo box and then select the County from a combo box.  Where the counties for only the selected state appear in the list.  In essence, strState is my variable from the combo box and is passed into the SQL statement.  I am new to access, so I hope this may help or give you an idea on passing variables.

Hope this helps,
Dan :Cool: 

Private Sub cboState_Change()
On Error GoTo Err_cboState_Change

    Dim strState As String

    strState = Me.cboState.Text

    Form_testform.cboCounty.SetFocus
    Form_testform.cboCounty.Text = ""

    Form_testform.cboCounty.RowSource = "SELECT Distinct(county) " _
    & "FROM PBG_Main WHERE sus_state = '" & strState & "'"

Exit_cboState_Change:
    Exit Sub

Err_cboState_Change:
    MsgBox Err.Description
    Resume Exit_cboState_Change

End Sub

----------

