Stewart/NeoPa,
I'm having a little trouble getting the syntax correct on a Dlookup. I have a form with an ID field on it. I want to match that ID to another field in a table. Once it finds a match, I want to retrieve the value of a different field in the same table. Here is the code: - =DLookUp("[Order Received]",("Orders"),"forms![mainform]![orderID]="[EbayOrder], [orderID]"
To clarify, I want to use the value of the order id field on the mainform to compare to the orderID in the EbayOrder table. If it finds a match, I want it to return the value of order received in the orders table.
15 2681 NeoPa 32,556
Recognized Expert Moderator MVP
I have split this question away from http://bytes.com/topic/access/answer...ill-not-update.
Please do not post your question in other members' threads as that is Thread Hihacking and is outlawed on this site. I appreciate this is your first post so nothing official to follow. Just take a glance at How to Ask a Question please, to ensure you understand some of the basic dos and don'ts of the site.
-Administrator.
PS. Welcome to Bytes!
NeoPa 32,556
Recognized Expert Moderator MVP
Let's forget DLookup() for the moment. The more usual way of providing that functionality is to build the form on a query where the two tables are already linked so that all the data is already available. Not only is it fundamentally easier, it also works more efficiently (Generally not noticeable in simple forms mind).
Hi. As NeoPa says, you will need a query which joins the tables you want to look up. DLookup is intended to look up a single value in a table or query. What it cannot do is look up a value in one table and return a value from another as you request, unless the source is itself a query which joins the tables concerned.
As mentioned, DLookup cannot join tables for you - you must devise a query to join the tables. That query could be the one you use as the recordsource of your form, in which case you will not need to use DLookup at all.
If you do use DLookup, fed by a suitable query containing the joined tables, you have to get the syntax right - your WHERE part is incorrect at present. I show an example of the correct syntax for your DLookup statement below, basing the lookup not on a table but a query called qryOrders, and assuming that OrderID is a numeric value: - =DLookUp("[Order Received]", "qryOrders", "[orderID] = " & [orderID])
However, I agree entirely with NeoPa that you should get the query approach right first before you devote any more time to DLookup.
-Stewart
Thanks for the insight and sorry about the posting error. I read the inital post and thought it might be an easy follow up question.
Back to my issue. I understand your directions. I created a seperate query named qryOrder Received to obtain the information needed. I plan to then use the Dlookup to obtain the corresponding value. However, I'm still struggling with the code. First, the record source for the order form is not order recieved so I'm guessing I need to specify the form name in the criteria portion of the Dlookup. Secondly, orderid is text. Does that mean it should be in quotes?
=DLookUp("[Order Received]", "qryOrder received", "[orderID] = " forms! [orderform]! ["orderID"])
I think I have the code figured, but I only get #error for results. Here is my code:
=DLookUp("[order received]","qryorder received","[order id] = " & Forms!mainform!order id)
Order ID is text. Does it matter that on the form, orderID has an input mask? I believe the value is stored without it.
- =DLookUp("order received","qryorder received","[order id] = [Forms]![mainform]![order id])
try that
things can get a bit unpredictable when you have spaces in names.
The #Error usually means that one of the names you are supplying within the function is incorrect or not recognised by Access. Dan 2K is correct about spaces - if there are spaces in the name of a control you must bracket the part with the spaces, [like this], or an error will occur.
You mention that Order ID is text. This changes the where clause, as the value you are comparing has to be supplied within single quotes as follows: - =DLookUp("[order received]","[qryorder received]","[order id] = '" & Forms!mainform![order id] & "'")
If the form control you are comparing is on the same form as the unbound control which is doing the DLookup you do not need to supply the Forms!Mainform part of the reference at all. Note that the [order id] on the left side of the expression is actually the name of the field within the query [QryOrder Received] which DLookup is running. The [Order ID] on the right is the name of the control on our form in which the value you are comparing is stored. The names are the same but they are not the same entities. - =DLookUp("[order received]","[qryorder received]","[order id] = '" & [order id] & "'")
@Dan2K: referring to form controls as part of the WHERE clause may not work; the query engine in some cases will supply the necessary value from the form, but whether or not DLookup itself will allow this in all cases is debatable. That is why the value of the control is normally supplied as part of the WHERE clause, concatenated in to the string using the ampersand operators.
-Stewart
Thanks, but, no cigar....
I made the changes but once I click OK, access converts the code to this:
=DLookUp("order received","qryorder received","[order ID] = " & Forms!mainform!order id)
i must admit i usually use " & me...... but i would use the other method (i posted) on the rare occasion, it eliminates the need for extra quotes/#'s (in my experience?)
Dan
Dieselrocks, no cigar or not perhaps you would actually use the syntax I suggested - where are the single quotes?? Where is the bracketing?? - =DLookUp("[order received]","[qryorder received]","[order ID] = '" & Forms!mainform![order id] & "'")
@Dan2k the Me notation works in VBA code only.
-Stewart
which is why i didnt suggest it :-)
actually i must of skipped some thread, didn't realise you was not in VBA
@Dan2kx
I guess this was an aside and not a suggestion then! -S
Stewart,
Thanks for your wisdom...it WORKS!!!! Glad I found this web site....I'm sure I'll be back!!
p.s. thanks to you too Dan2Kx
@Dieselrocks - glad it's now working for you, and
Welcome to Bytes!
-Stewart
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: JLM |
last post by:
What am I missing here?
I have a form where I enter a "Class Code". This value corresponds to what
sits in table "class code descriptions" along with the "title" of each
"class code." Key...
|
by: Kalvin Schroder |
last post by:
I am fairly new to Access, and am trying to put together an invoice
form. The main form in called InvoiceDetailFm. Source is the table
InvoiceDetail and has invoice number, saleman, and CustID as...
|
by: MLH |
last post by:
I have tried using DLookUp in this manner...
If DLookUp("","tblClients","='2021234567'") Then
MsgBox "Found it!"
End If
I am wondering if that is a misuse of the DLookUp command?
Type...
|
by: ctyrrell |
last post by:
I have read with interest the many discussions of the 3048 Error:
Cannot open any more databases. I understand how the number of open
Table ID's causes the problem. My question has to do with the...
| |
by: Christine Henderson |
last post by:
I have a problem using the above function in the following simplified
circumstance:
In the lookup table called "Klms Travelled" I have 3 fields, eg:
Receiver Name Receiver Suburb ...
|
by: MLH |
last post by:
DLookup("", "tblPreliminaryVINs",
"=Forms!frmVINODO!SerialNum")
is giving me a Type Mismatch error. That's confusing to me
and I don't know how to circumvent it. The field in...
|
by: Don |
last post by:
Can someone help me fix my DLookup problem. I'm far from proficiency with
Access. I've been creating databases for several years for work with the
help of many of you and trial and error.
I have...
|
by: |
last post by:
In my database I have a 'control table' in which basic info is stored about the application, for instance the application's path and the name of the company that is using it. In all of the...
|
by: rleepac |
last post by:
This is a little complicated but I'll do my best to explain. In my db I have a table called L_AgeCorrection which has the following fields: Age, Sex, Frequency, AgeValue
This is a table used to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
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: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |