Link to home
Start Free TrialLog in
Avatar of ggodwin
ggodwinFlag for United States of America

asked on

I need to query based on a selection in a form.

I want to push a button called "Save". This will run a query that will be eventually create a report/pdf.
For now, I'm just working on the query that will select the record that I need. I'm trying to run a query based on a selection in a form/table.

At any give time I will have a record in my QREVALE form/table. The field is called TagNumber.
Below is a query that I have that does NOT call a special record. I want this query to only call the record that has the matching TagNumber from the form.

any suggestions?


SELECT 
SkpiUpdate.Date, 
QREVALUE.TagNumber, 
QREVALUE.QPRQPINumber, 
SkpiUpdate.NAMC, 
FROM QREVALUE INNER JOIN SkpiUpdate ON QREVALUE.ScrapRecordTag = SkpiUpdate.ScrapRecordTag;

Open in new window

Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

What database product?  What form language/product?

...
WHERE SkpiUpdate.ScrapRecordTag = @SelectedTagVariable

Sorry but that doesn't answer my questions.


To get the quickest answers to your questions, we need to get it if front of the best Experts.  To do that, we need to know what products/programming languages you are using so we can add or change the Topic Areas the question is posted in.

Avatar of ggodwin

ASKER

Andrei Fomitchev,
Sorry for my delay in responding. I had another issue become more urgent.

I'm getting an "Extra in query expression" error with my syntax. I have two WHERE conditions.


SELECT SkpiUpdate.Date, SkpiUpdate.NAMC,
 SkpiUpdate.[Supplier Code], SkpiUpdate.[Part Number],
 SkpiUpdate.[Part Name], SkpiUpdate.Quantity,
 SkpiUpdate.[Defect Description],
 QREVALUE.ProblemDescription,
 SkpiUpdate.[Model Code],
FROM QREVALUE INNER JOIN SkpiUpdate ON QREVALUE.ScrapRecordTag = SkpiUpdate.ScrapRecordTag
WHERE (((SkpiUpdate.[Fault Type])="PPM")) AND SkpiUpdate.ScrapRecordTag = @SelectedTagVariable);

Open in new window

Count your parenthesis in the where clause.  You have an extra one.


Since it is an AND and only two options, you don't need any parenthesis.

Avatar of ggodwin

ASKER

I got the query working however, it is NOT pulling the record that is entered in the WHERE statement. Its just pulling a blank.  

Currently, I am entering the record manually.

I want to call this query while having a THE record called into a form.  The query based on that selection in the WHERE Statement.
Do i need to have a reference to the form?

SELECT SkpiUpdate.Date, SkpiUpdate.NAMC,
 SkpiUpdate.[Supplier Code],
 SkpiUpdate.[Part Number],
 SkpiUpdate.[Part Name],
 SkpiUpdate.Quantity,
 SkpiUpdate.[Defect Description],
 QREVALUE.ProblemDescription,
 SkpiUpdate.[Model Code],
 SkpiUpdate.[Fault Type],
 SkpiUpdate.InitialQuantity,
 QREVALUE.HowFound,
 QREVALUE.QREConfirmation,
 QREVALUE.InterimAction,
 QREVALUE.SortedQuantity,
 QREVALUE.SortRejects,
 QREVALUE.[SortCompletion Date],
 QREVALUE.ReportDueDate,
 QREVALUE.DateCode,
 QREVALUE.ToyotaRank,
 QREVALUE.PartsShippedDate,
 QREVALUE.ShipmentTracking,
 QREVALUE.ShippingCarrier,
 QREVALUE.DueDate
FROM QREVALUE INNER JOIN SkpiUpdate ON QREVALUE.ScrapRecordTag = SkpiUpdate.ScrapRecordTag
WHERE (((SkpiUpdate.[Fault Type])="PPM")) And SkpiUpdate.ScrapRecordTag=[@SelectedTagVariable];

Open in new window

I don't know what you mean by "form".  I previously asked for what  products/programming languages you are using but never received a response.

ASKER CERTIFIED SOLUTION
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ggodwin

ASKER

See the attached image.

I am using Access

Form Name: QREVALUE

Control Source: QREVALUE TABLE.TagNumber

I want the TAGNUMBER that is in the form/filter to be passed into the below query as the criteria in the Where statement.

User generated image
SELECT SkpiUpdate.Date,
 SkpiUpdate.NAMC,
 SkpiUpdate.[Supplier Code],
 SkpiUpdate.[Part Number],
 QREVALUE.HowFound,
 QREVALUE.QREConfirmation,
 QREVALUE.InterimAction,
FROM QREVALUE INNER JOIN SkpiUpdate ON QREVALUE.ScrapRecordTag = SkpiUpdate.ScrapRecordTag
WHERE (((QREVALUE.TagNumber)=[@SelectedTagVariable]) AND ((SkpiUpdate.[Fault Type])="PPM"));

Open in new window

Avatar of ggodwin

ASKER

Wait.. I found an error
Avatar of ggodwin

ASKER

User generated imageSo now, I can manually add the TagNumber and the action produces what I want.
I just need to be able to pass that TagNumber to the SelectedTagVariable in my WHERE STATEMENT.

WHERE (((QREVALUE.TagNumber)=[@SelectedTagVariable])
Avatar of ggodwin

ASKER

What that go in my Sub for the Button Command?

Private Sub Share_Click()
DoCmd.OpenQuery "qSaveQREValueReport"
End Sub

Open in new window

Should go in the saved query but I haven't done any Access programming for many years.

[@SelectedTagVariable] - it makes just text @SelectedTagVariable - it is not a value from variable. To make it work, remove brackets []. It should be just @SelectedTagVariable.