Query based off a form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form to make it visually appealing for users to run queries. It has
six different criteria ex. state, age, name, department, ECT... The form will
only return results if all six criteria are filled. How can I make it so the
query will run no matter the criteria I put in? For example, if I just want
all the individuals from Illinois that work for Human Resources but I don't
care about the age or name. Like I said earlier right now the only way it
returns and valid data is if all criteria are filled in. Here is the criteria
for year in the query the rest look similar.. Any help if this makes sence at
all would be appreciated !!

Year
tblmain
[Forms]![frminfo]![cboyear]
 
I notice individuals adding their sql ststement here is what it looks like
for mine!

SELECT tblmain.Year, tblmain.Name, tblmain.State, tblmain.Department,
tblmain.Race, tblmain.Gender, tblmain.[Q/UQ]
FROM tblmain
WHERE (((tblmain.Year)=[Forms]![frminfo]![cboyear]) AND
((tblmain.State)=[Forms]![frminfo]![cbostate]) AND
((tblmain.Department)=[Forms]![frminfo]![cbodepartment]) AND
((tblmain.Race)=[Forms]![frminfo]![cborace]) AND
((tblmain.Gender)=[Forms]![frminfo]![cbogender]) AND
((tblmain.[Q/UQ])=[Forms]![frminfo]![cboQ/UQ]));
 
Ryan said:
I notice individuals adding their sql ststement here is what it looks like
for mine!

SELECT tblmain.Year, tblmain.Name, tblmain.State, tblmain.Department,
tblmain.Race, tblmain.Gender, tblmain.[Q/UQ]
FROM tblmain
WHERE (((tblmain.Year)=[Forms]![frminfo]![cboyear]) AND
((tblmain.State)=[Forms]![frminfo]![cbostate]) AND
((tblmain.Department)=[Forms]![frminfo]![cbodepartment]) AND
((tblmain.Race)=[Forms]![frminfo]![cborace]) AND
((tblmain.Gender)=[Forms]![frminfo]![cbogender]) AND
((tblmain.[Q/UQ])=[Forms]![frminfo]![cboQ/UQ]));
Ryan said:
I have a form to make it visually appealing for users to run queries. It has
six different criteria ex. state, age, name, department, ECT... The form will
only return results if all six criteria are filled. How can I make it so the
query will run no matter the criteria I put in? For example, if I just want
all the individuals from Illinois that work for Human Resources but I don't
care about the age or name. Like I said earlier right now the only way it
returns and valid data is if all criteria are filled in. Here is the criteria
for year in the query the rest look similar.. Any help if this makes sence at
all would be appreciated !!

Year
tblmain
[Forms]![frminfo]![cboyear]


Well, this gets rather messy, but should work:

Year
tblmain
[Forms]![frminfo]![cboyear] OR [Forms]![frminfo]![cboyear]
Is Null

But I think that after you become more proficient with all
this stuff, you should use VBA code to create the SQL
statement so that you only include the criteria that uaers
actually enter.
 

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

Back
Top