Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query Issueesss...!!! Heellppp

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Here is the problem. I have two forms. My main form is called General. and then I have another form called "Victim" I placed "Victim" as a subform into General and now I am trying to create a query. Here is the problem. I have that SQL code down below in a query called "Victim Query" the problem that is arising is when the user is in the General form (which contains the Victim subform) and types in information for Victim to be searched a box pops up that says "Enter Parameter Value" Forms.Victim.Last Name. I do not know why it is doing this. When I open the Victim Form by itself the query works fine, the problem only happens when I try to run the query from the General form. I have to be able to run the query within the General Form so if anyone has any idea how to fix the problem it would be greatly appreciated

SELECT [Victim].[Last Name], [Victim].[First Name], [Victim].[Res Add], [Victim].[Res Phn], [Victim].[Bus Add], [Victim].[Bus Phn], [Victim].[Race], [Victim].[Sex], [Victim].[Age], [Victim].[Occupation]
FROM Victim

WHERE ([Victim].[Last Name]=[forms].[Victim].[Last Name] Or [forms].[Victim].[Last Name] Is Null) and ([Victim].[First Name]=[forms].[Victim].[First Name] or [forms].[Victim].[First Name] is Null);
 
If your First Name and Last Name are strings, then add the following in the beginning of the SQL statement before the SELECT:

PARAMETERS [forms].[Victim].[Last Name] Text ( 255 ), [forms].[Victim].[First Name] Text ( 255 );

You can also just chnge it in the Design view, go to the Query Menu, and you should have the Parameters Option there, Now enter all the References you have exactyl as you have written them, in this case you have 2 of them "[forms].[Victim].[First Name]" And "[forms].[Victim].[Last Name]" define what datatype you will be using. eg, Text, date, etc...
Eldaria

That was my 25cent** of opinion.

** Inclusive Intrest, tax on interest, Genral tax, Enviromental tax, Tax, and tax on intrest, tax on fees, tax on tax, and other Various taxes and fees.
 
That Didnt' Work. It still gives me the 'Enter Parameter Value' message. The fields [first name], [last name] etc...are fields which the user enters data into and the person has the option of leaving one or all blank. SO if they just want to search by last name, it will bring up all matching data. If that helps
 
Ahhhh, I just saw what the problem is...
You have a suibform, you have to rfer to the subform, I have some code that is doing the same, The easiest way of doing this would be to open the Main form with the child for on.
then go to the query, and use the Expression Builder, this way you can select Forms, then Loaded Forms, and then the Main form, after that you should select the Child/sub form, and the field you want.
My Expression looks like this:
[Forms]![frm_Menu_Main]![Child27].[Form]![Combo4]

Eldaria

That was my 25cent** of opinion.

** Inclusive Intrest, tax on interest, Genral tax, Enviromental tax, Tax, and tax on intrest, tax on fees, tax on tax, and other Various taxes and fees.
 
Thanks Eldaria for all your help. Below is the fixed code (i think). Is that the proper syntax? I'm not sure if i'm writing something incorrect. It doesn't give me that error message anymore but now no data appears when I run the query.

WHERE ([Victim].[Last Name]=[forms]![General]![Victim]![Last Name]
Or [forms]![General]![Victim].[Form]![Last Name] Is Null);
 
Hmm, ok, so I guess it is refereing to the right place now,
What is it exactly that this query is doing?
I guess it is something like, you want to give the option of leaving out the name it will show everything.

My knowledge on the SQL part is very limited, And I tried doing exactly the thing you are showing here, and I can only get it to work when you work directly on the query, and not refering to a Form, Maybe someine else can help with that.
My solution then was to make the query on the fly, by letting the user select what he wants to search on, and then use QueryDefs to build a result table.

Eldaria

That was my 25cent** of opinion.

** Inclusive Intrest, tax on interest, Genral tax, Enviromental tax, Tax, and tax on intrest, tax on fees, tax on tax, and other Various taxes and fees.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top