简体   繁体   中英

Is there a way to filter ms-Access records based on two criteria?

i'm not experinced when it comes to Microsoft Access and i'm having diffuclties completeling a task at my internship. I was given a list of records and i'm supposed to create a query that picks random records (winners) based on the country and the year of choice. I was able to do the randomizing bit by implementing the following SQL code:

     `SELECT TOP 10 Sheet2.name, Sheet2.country, Sheet2.Year
      FROM Sheet2
      ORDER BY Rnd(-(100000*ID)*Time());

`

My problem is that I want to choose the number of winners and select the country from dropdown list in my form and the year and filter the records based on the selection.

Any help would be appreciated!

This should work:

  SELECT TOP 10 Sheet2.name, Sheet2.country, Sheet2.Year
  FROM Sheet2
  WHERE Sheet2.country = [Forms]![YourFormName]![cboCountry]
  AND Sheet2.Year = [Forms]![YourFormName]![txtYear]
  ORDER BY Rnd(-(100000*ID)*Time());

where cboCountry and txtYear are the two controls on your form.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM