Results 1 to 2 of 2

Thread: SELECT TOP x - MS Access SQL Query problem

  1. #1
    Join Date
    Nov 2002
    Location
    England
    Posts
    2

    SELECT TOP x - MS Access SQL Query problem

    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

  2. #2
    Join Date
    Jan 2003
    Location
    Dallas, TX
    Posts
    6

    Lightbulb Maybe this will help

    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

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •