Query to return information from table.

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

Guest

This is my problem and I have struggled with it for a week with no answers:
I am running a query that returns a part number; I then want the query to
bring up a value that is in a table to compare the information. Example:
Query returns PartNumber PT-1234 I want to it to go to PartNumberTable and
return for PartNumber PT-1234 the cost. I am not very good at this so
detailed information would be appreciated. Access 2007 Thanks in advance
for any help.
 
One way will be using the DlookUp function in the query to retrieve the code.
Create a new field in the query and write

TableCost: DlookUp("[Cost]","[PartNumberTable]","[PartNumber] = '" &
[PartNumber] & "'")

The other way will be to link the PartNumberTable to the query created by
the PartNumber field.

Note: Make sure that the name of the fields and the table in the dlookup are
correct
 
It almost did it. It prompts me for the part number and if I imput a number
it then returns the information that I need for that one number. I need it
to return the information for all the part numbers in the query. What do I
need to change for that? Thanks again.

Roy

SELECT [Time Sheet].JobNumber AS [Job #], First([Time Sheet].PartNumber) AS
Part, Sum([Time Sheet].OrderQuanity) AS [Order], Sum([Time
Sheet].Quanityproduced) AS [Qt Produced], Sum([Time Sheet].ScrapNumberParts)
AS Scrap, Sum([Time Sheet].TimeCharged) AS [Time], Sum([Time
Sheet].JobSetUpTime) AS [Set-Up], ([Qt Produced]-[Scrap])/[Time] AS [Parts
Hr], DLookUp("[PartPerHour]","[Part Numbers]","[PartNumber]='" & [Part] &
"'") AS Compare
FROM [Time Sheet] LEFT JOIN [Part Numbers] ON [Time Sheet].ID = [Part
Numbers].ID
GROUP BY [Time Sheet].JobNumber, DLookUp("[PartPerHour]","[Part
Numbers]","[PartNumber]='" & [Part] & "'")
ORDER BY [Time Sheet].JobNumber;


Ofer Cohen said:
One way will be using the DlookUp function in the query to retrieve the code.
Create a new field in the query and write

TableCost: DlookUp("[Cost]","[PartNumberTable]","[PartNumber] = '" &
[PartNumber] & "'")

The other way will be to link the PartNumberTable to the query created by
the PartNumber field.

Note: Make sure that the name of the fields and the table in the dlookup are
correct

--
Good Luck
BS"D


SailorRoy said:
This is my problem and I have struggled with it for a week with no answers:
I am running a query that returns a part number; I then want the query to
bring up a value that is in a table to compare the information. Example:
Query returns PartNumber PT-1234 I want to it to go to PartNumberTable and
return for PartNumber PT-1234 the cost. I am not very good at this so
detailed information would be appreciated. Access 2007 Thanks in advance
for any help.
 
You can create a new query based on the first query that doesn't include the
dlookup, and in the new query add the dlookup


SELECT QueryName.*, DLookUp("[PartPerHour]","[Part
Numbers]","[PartNumber]='" & [Part] & "'") AS Compare
FROM QueryName

--
Good Luck
BS"D


SailorRoy said:
It almost did it. It prompts me for the part number and if I imput a number
it then returns the information that I need for that one number. I need it
to return the information for all the part numbers in the query. What do I
need to change for that? Thanks again.

Roy

SELECT [Time Sheet].JobNumber AS [Job #], First([Time Sheet].PartNumber) AS
Part, Sum([Time Sheet].OrderQuanity) AS [Order], Sum([Time
Sheet].Quanityproduced) AS [Qt Produced], Sum([Time Sheet].ScrapNumberParts)
AS Scrap, Sum([Time Sheet].TimeCharged) AS [Time], Sum([Time
Sheet].JobSetUpTime) AS [Set-Up], ([Qt Produced]-[Scrap])/[Time] AS [Parts
Hr], DLookUp("[PartPerHour]","[Part Numbers]","[PartNumber]='" & [Part] &
"'") AS Compare
FROM [Time Sheet] LEFT JOIN [Part Numbers] ON [Time Sheet].ID = [Part
Numbers].ID
GROUP BY [Time Sheet].JobNumber, DLookUp("[PartPerHour]","[Part
Numbers]","[PartNumber]='" & [Part] & "'")
ORDER BY [Time Sheet].JobNumber;


Ofer Cohen said:
One way will be using the DlookUp function in the query to retrieve the code.
Create a new field in the query and write

TableCost: DlookUp("[Cost]","[PartNumberTable]","[PartNumber] = '" &
[PartNumber] & "'")

The other way will be to link the PartNumberTable to the query created by
the PartNumber field.

Note: Make sure that the name of the fields and the table in the dlookup are
correct

--
Good Luck
BS"D


SailorRoy said:
This is my problem and I have struggled with it for a week with no answers:
I am running a query that returns a part number; I then want the query to
bring up a value that is in a table to compare the information. Example:
Query returns PartNumber PT-1234 I want to it to go to PartNumberTable and
return for PartNumber PT-1234 the cost. I am not very good at this so
detailed information would be appreciated. Access 2007 Thanks in advance
for any help.
 

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