473,387 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Query not working

Fspinelli
Hi and Happy New Year!

I have a QBF and a big challenge. I can't seem to get it to work...

I have two tables:
Contact
Contact_Type

I have a form:
Query_Window

On that form end users should be able to tick radio buttons (one or many - there are 16 of them) and/or use a text box where they can enter a full or partial word (one of these), and a few drop down boxes (three of these) that give the end user choices.

I have the query:
qrySearchStatus

To test the form, I chose a few radio buttons, a state and a priority, as soon as I click on the command button “Run Query” a window comes up and says:

Forms!Query_Window!TxtCompany
And it does this for each control and finally, no results. No matter what I chose on the form - even if it's just one radio button, or adding a few letters in the text box...

What am I doing wrong? The SQL to the query (qrySearchStatus) is below. I have no clue what to do.

Thank you!!!

SELECT
Contacts.Company,
Contacts.State,
Contacts.Country,
Contacts.Priority,
Contact_Type.BD,
Contact_Type.CO,
Contact_Type.CP,
Contact_Type.EN,
Contact_Type.FoF,
Contact_Type.FAM,
Contact_Type.FC,
Contact_Type.FO,
Contact_Type.GP,
Contact_Type.INS,
Contact_Type.IP,
Contact_Type.NHF,
Contact_Type.PB,
Contact_Type.SM,
Contact_Type.SWF,
Contact_Type.TH

FROM Contact_Type INNER JOIN Contacts ON Contact_Type.ContactID = Contacts.ContactID

WHERE

(((Contacts.Company) Like "*" & [Forms]![Query_Window]![TxtCompany] & "*")
AND
((Contacts.State)=[forms]![query_window]![cboState])
AND ((Contacts.Country)=[forms]![query_window]![cboCountry])
AND ((Contacts.Priority)=[forms]![query_window]![cbPriority])
AND ((IIf([forms]![Query_Window]![cb1],[BD]=True,True))=True)
AND ((IIf([forms]![Query_Window]![cb2],[CO]=True,True))=True)
AND ((IIf([forms]![Query_Window]![cb3],[CP]=True,True))=True)
AND ((IIf([forms]![Query_Window]![cb4],[EN]=True,True))=True)
AND ((IIf([forms]![Query_Window]![cb5],[FAM]=True,True))=True)
AND ((IIf([forms]![Query_Window]![cb6],[FC]=True,True))=True)
AND ((IIf([forms]![Query_Window]![cb7],[FO]=True,True))=True)
AND ((IIf([forms]![Query_Window]![cb8],[FoF]=True,True))=True)
AND ((IIf([forms]![Query_Window]![cb9],[GP]=True,True))=True)
AND ((IIf([forms]![Query_Window]![cb10],[INS]=True,True))=True)
AND ((IIf([forms]![Query_Window]![cb11],[IP]=True,True))=True)
AND ((IIf([forms]![Query_Window]![cb12],[NHF]=True,True))=True)
AND ((IIf([forms]![Query_Window]![cb13],[PB]=True,True))=True)
AND ((IIf([forms]![Query_Window]![cb14],[SM]=True,True))=True)
AND ((IIf([forms]![Query_Window]![cb15],[SWF]=True,True))=True)
AND ((IIf([forms]![Query_Window]![cb16],[TH]=True,True))=True))
OR (((Contacts.Company) Is Null)
AND ((Contacts.Country) Is Null)
AND ((Contacts.Priority) Is Null))
ORDER BY Contacts.Company;
Jan 11 '11 #1

✓ answered by beacon

I wasn't talking about the query. You said that when you click Run, a window pops up that says Forms!Query_Window!TxtCompany, right? Is the window that pops up asking you to type anything into it or does it look like an error window?

If it's an input box it will look the attachment I've added below.

11 1684
beacon
579 512MB
Hi Fspinelli,

When you say...

To test the form, I chose a few radio buttons, a state and a priority, as soon as I click on the command button “Run Query” a window comes up and says:

Forms!Query_Window!TxtCompany
And it does this for each control and finally, no results. No matter what I chose on the form - even if it's just one radio button, or adding a few letters in the text box...
...is the window an input box asking you to type in data? Your SQL shows references to your form, so if you run the query, the query is going to look to the form for the parameters it needs to compile.

If you were to add a command button on the form and add code to the OnClick event for the command button that says...

Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenQuery "qrySearchStatus"
  2.  
...your query would likely open without the input boxes appearing because you've now passed the parameters to the query. If the form isn't open or filled out when you click Run in the query, the query doesn't know what values to use where you have text like Forms!Query_Window!TxtCompany.

If this doesn't make sense, or if you want a visual to help you along, check out this site, http://www.fontstuff.com/access/acctut08.htm.

Hope this helps,
beacon
Jan 11 '11 #2
no, it's not a query prompting for an end user to enter anything.

This is a form where they can make choices and run the query. The choices are radio buttons (16 of them). One or many could be ticked. Also on that form is a text box in case they want to query companies that have certain letters in them. Then there are also combo boxes. The combo boxes would be state, country and priority.

If the end user ticked a few radio buttons all records with those choices will come up. If the end user enters just a few letters in the text box, just companies with those letters would come up. If they had those radio buttons, the text box with letters AND they chose NY from the state drop down box, and 1 from the priority drop down box, then those records only should show up.

End user does not have to chose one or all, they could just choose to look at companies in NY or only those with a status of FoF, the query should ignore the null values (I have "is null" in the OR portion of the query column).

still not working - I have half a head of hair left...I am using your very nice tutorial, but it's not helping me with this particular inquiry.

Thank you very much, Beacon!
Jan 11 '11 #3
beacon
579 512MB
I wasn't talking about the query. You said that when you click Run, a window pops up that says Forms!Query_Window!TxtCompany, right? Is the window that pops up asking you to type anything into it or does it look like an error window?

If it's an input box it will look the attachment I've added below.
Attached Images
File Type: bmp untitled.bmp (104.4 KB, 156 views)
Jan 11 '11 #4
your attachment is exactly what it looks like! every single control on the form wants me to do something like that! lol...

I am missing a big thing in my code, I'm sure!
Jan 11 '11 #5
beacon
579 512MB
No, you aren't missing anything in your code...You just need to open the form and use the form to open the query instead of running the query by itself.

The query is expecting values from your form, but since the form isn't open, the input boxes pop up asking you for the values instead. So if you open your form in Design View and add a command button, then change the OnClick event to say the following:

Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenQuery "qrySearchStatus"
  2.  
...when you run the form, enter data into all of the fields, and then click the button, the query will open with the data it needs and the input boxes won't appear.
Jan 11 '11 #6
Yea, I tried that code you gave me and I still get those input boxes. Perhaps I have things in the wrong area of the query? In the query I have the 16 options but also, next to them unchecked rows with that code in it.

Example:

BD is from contact_types. cb1 is the name of the radio button for BD on the form. BD shows in my query and checked so we can see it. Next to it is a colum but with this code:
(IIf([forms]![Query_Window]![cb1],[BD]=True,True))

Each one (BD is rb1, CO is rb2, CP is rb3...etc.

So I must be confusing it as much as it is confusing me!



I don't know how to attach else I would give you a picture of what my query looks like.
Jan 11 '11 #7
Beacon - found it!!

attached is a sample of my query. There are 16 "status" options but I just put three down. At least you catch my drift (i hope.)

Thank you Thank you Thank you!!
Attached Images
File Type: jpg query.jpg (36.0 KB, 185 views)
Jan 11 '11 #8
beacon
579 512MB
Can you post pics of the form you're using?
Jan 12 '11 #9
Here's a screen pic of my form.

p.s. I've added a subform (where the results should show up). Hence, why I have not mentioned it...

Thank you for all of your efforts!
Attached Images
File Type: jpg query_window.jpg (94.9 KB, 189 views)
Jan 12 '11 #10
beacon
579 512MB
I tried to recreate your database and I think I was able to get it to work.

To get the Company to work, keep it as is.

To get the checkboxes to work, I removed all of the...

Expand|Select|Wrap|Line Numbers
  1. (IIf([forms]![Query_Window]![cb1],[BD]=True,True)) 
  2.  
...and typed...

Expand|Select|Wrap|Line Numbers
  1. [Forms]![Query_Window]![BD]
  2.  
...into the first "Or" Criteria underneath the BD column. I did this for all of the checkboxes (I only used three when I tried to recreate it, but it should work for you, nonetheless).

Just for reference, here's the SQL from my test query:

Expand|Select|Wrap|Line Numbers
  1. SELECT CheckBox.TestID, 
  2.        CheckBox.Company, 
  3.        CheckBox.Check1, 
  4.        CheckBox.Check2, 
  5.        CheckBox.Check3
  6. FROM CheckBox
  7. WHERE 
  8. (((CheckBox.Company) Like "*" & [Forms]![frmCheckBox]![Company] & "*") 
  9. OR 
  10. ((CheckBox.Check1)=[Forms]![frmCheckBox]![AB]) 
  11. AND 
  12. ((CheckBox.Check2)=[Forms]![frmCheckBox]![CD]) 
  13. AND 
  14. ((CheckBox.Check3)=[Forms]![frmCheckBox]![EF]));
  15.  
Jan 19 '11 #11
Thank you very much, beacon!

I'll give it a try!
Jan 19 '11 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Cory | last post by:
When I run the subroutine testEmailContacts the msgbox says that there is only 1 record. The sql for qyEmailContactsQyCard is below. There is over 3000 records in the table "tbl:Contact". What am i...
14
by: Darin | last post by:
I have a table that I want to delete specific records from based on data in other tables. I'm more familiar with Access '97, but am now using 2003, but the database is in 2000 format. In '97, I...
17
by: erikcw | last post by:
Hi all, I'm trying to run the following query: amember_db = MySQLdb.connect(host="localhost", user="**********", passwd="*****", db="*******") # create a cursor self.amember_cursor =...
4
by: lorirobn | last post by:
Hi, I have a report displaying items that are missing from a room. I created 2 queries, the first getting the items IN the room, and the second being an "unmatched" query that references the...
7
by: MrHelpMe | last post by:
Sorry everyone, NOTE: I have posted this question to another site but unfortunately, am not getting the answers I need only because those helping haven't worked with ASP. I am in desperate...
4
by: Stan | last post by:
I am using MS Office Access 2003 (11.5614). My basic question is can I run a query of a query datasheet. I want to use more that one criteria and can not get that query to work. I thought I...
11
by: olobraecky | last post by:
Hi all, I am new to perl - just started to learn it a few weeks ago. Basically, what I am trying to do is a "register user" script using a mySQL database. I have managed to do the insert query...
1
by: Tobias | last post by:
Hello, I have a data entry form. When data is entered in one of the fields I would like that data to be used to lookup info in a query and have that displayed in the form. The main form is a...
14
by: Rich P | last post by:
Hi Sara, If you try it this way - you may have better luck Dim strSql As String strSql = "INSERT INTO tblPOCancels ( PONum, PODate, DateEntered, MerchantKey,VendorKey, POApproved, " _ &...
0
prabirchoudhury
by: prabirchoudhury | last post by:
CRITERIA; +-------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------------+--------------+------+-----+---------+-------+...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.