473,385 Members | 1,813 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,385 software developers and data experts.

Dlookup will not pull needed value from query

I am trying to use the Dlookup expression in a macro to pull the value from the "Price" field in the following query. The query works fine and the Dlookup function did as well until I added a new field to the "Contracts" table called "ContractYear".

Expand|Select|Wrap|Line Numbers
  1. SELECT Contracts.ID, Contracts.Commodity, Contracts.Date, Contracts.ContractYear, Contracts.Option, Contracts.[Contract No], Contracts.Bushels, Contracts.Price, Contracts.[Bushels Remaining]
  2. FROM Customer INNER JOIN Contracts ON Customer.ID = Contracts.ID
  3. GROUP BY Contracts.ID, Contracts.Commodity, Contracts.Date, Contracts.ContractYear, Contracts.Option, Contracts.[Contract No], Contracts.Bushels, Contracts.Price, Contracts.[Bushels Remaining]
  4. HAVING (((Contracts.ID)=[Forms]![Transactions]![Customer ID]) AND ((Contracts.Commodity)=[Forms]![Transactions]![Commodity]) AND ((Contracts.ContractYear)<=Year([Forms]![Transactions]![Date])) AND ((Contracts.Option)=[Forms]![Transactions]![Option]) AND ((Contracts.[Bushels Remaining])>0))
  5. ORDER BY Contracts.ID, Contracts.Commodity, Contracts.Date;
  6.  
The Dlookup expression that had previously worked follows.
Expand|Select|Wrap|Line Numbers
  1. DLookUp("[Price]","Open Contracts","[Option]='" & [Forms]![Transactions]![Option] & "'" & " And [Commodity]='" & [Forms]![Transactions]![Commodity] & "'" & " And [ID]='" & [Forms]![Transactions]![Customer ID] & "'")
  2.  
When I try to add the extra code for the ContractYear field, I get an error that the expression is too long. I may not need all the criteria in the Dlookup expression, but at this point are at a lost as what to do. The query itself pulls the data I need and as long as Dlookup pulls the price from the first record generated by the query I should be OK.

Any assistance is appreciated.

Thank you.

Roger
Oct 19 '07 #1
3 2428
Rabbit
12,516 Expert Mod 8TB
Please use Code tags.

It seems to me that you've already included all the criteria in the query. There should be no need to include the criteria again in the DLookup.
Oct 19 '07 #2
If the "Open Contracts" query already has the criteria specified then would I use the DLookup expression as shown below? When I tried it yesterday using this format, it didn't seem to work. If the query finds more than one record, how does DLookup know which record to pull the "Price" information from? Is it the first record?

code:

DLookUp("[Price]","Open Contracts")

Thanks

Roger
Oct 21 '07 #3
Rabbit
12,516 Expert Mod 8TB
You might have to use this:
DLookUp("[Price]","[Open Contracts]")

But yes, if the query has all the criteria you need, you don't need to include them in the DLookup if you're going to lookup in the query.

If there are multiple records that match, then it will return the first one it finds.
Oct 21 '07 #4

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

Similar topics

1
by: KLAU | last post by:
I have a field that retrieves information from an expression in a query. I have used a DLookup function to get the calculated field from the query. However, the relationship is 1-to-many so one...
7
by: Tony Williams | last post by:
Does DLookup work in an expression in a query? I have this expression -(DLookUp("","tblmaintabs","= ")) Which works fine as a calculated control on a form but when I try to use it in a query as an...
1
by: MLH | last post by:
I have a query that looks up records in tblReturnReceipts and other related tables. One of the other tables is tblCorrespondence. The resulting dynaset consists of five records. Each has a unique ...
2
by: c.kurutz | last post by:
Hello everyone. I have a problem with looking up pricing. Here is what I have so far: TABLES tblItems: itemid itemdescription itemunit (each, roll, square foot) location1price
1
by: TerryD | last post by:
I have a form that has an unbound text field that I am using DLookup in to display the values from a Temp Table. My program calls for me pushing a button to print a report, which runs a query first...
1
by: aharding | last post by:
Hello! I am using Access 2003 I have been playing with DLookup all morning and have not been successful yet. I have never used this function...and have some limited experience with code. I...
1
by: msbranh | last post by:
I have a report I am needing to run and have it e-mailed to a specific person. Basically the report runs off a query that when ran it ask which Market I want to run. I enter in 415 for an example....
1
by: jzalar | last post by:
I am using Access 97 (No choice) and I trying to get the VBA to do this. 1. Open a query "X-Misses-1" 2. Pull the value from the field "total misses" 3. Use that value in a loop to run an...
4
beacon
by: beacon | last post by:
I have a report that is pulling data from a query. The query gets sent a parameter from a form. The information on the form is correct, but my summary section is incorrect. The reason the summary...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.