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". - SELECT Contracts.ID, Contracts.Commodity, Contracts.Date, Contracts.ContractYear, Contracts.Option, Contracts.[Contract No], Contracts.Bushels, Contracts.Price, Contracts.[Bushels Remaining]
-
FROM Customer INNER JOIN Contracts ON Customer.ID = Contracts.ID
-
GROUP BY Contracts.ID, Contracts.Commodity, Contracts.Date, Contracts.ContractYear, Contracts.Option, Contracts.[Contract No], Contracts.Bushels, Contracts.Price, Contracts.[Bushels Remaining]
-
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))
-
ORDER BY Contracts.ID, Contracts.Commodity, Contracts.Date;
-
The Dlookup expression that had previously worked follows. -
DLookUp("[Price]","Open Contracts","[Option]='" & [Forms]![Transactions]![Option] & "'" & " And [Commodity]='" & [Forms]![Transactions]![Commodity] & "'" & " And [ID]='" & [Forms]![Transactions]![Customer ID] & "'")
-
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
3 2428
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.
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
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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 ...
|
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
|
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...
|
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...
|
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....
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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
|
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...
|
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...
|
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: 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...
| |