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

Dlookup no returning a value

46
I am having trouble getting my dlooup to return any value. I have 5 that I am doing in my vba code. The first two work great but the other three don't return any value or errors.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Report_Load()
  2. Text72 = DLookup("[address]", "Customer Database", "school='" & Reports![Create Route Invoice]![School] & "'")
  3. Text75 = DLookup("[city State, Zip Code]", "Customer Database", "school='" & Reports![Create Route Invoice]![School] & "'")
  4. Text93 = DLookup("[PRP]", "Route Pricing per School", "school='" & Reports![Create Route Invoice]![School] & "'")
  5. [Excess time per Hour] = DLookup("[ETPH]", "Route Pricing per School", "School='" & Reports![Create Route Invoice]![School] & "'")
  6. [Excess Mileage Rate per Mile] = DLookup("[EMRPM]", "Route Pricing per School", "School='" & Reports![Create Route Invoice]![School] & "'")
  7. '[number of trips]
  8. End Sub
I did check to see if school data type matches. Which it does. The only real difference between the two and the bottom three is the table that its is lookup up the values from. I have triple checked the spelling of all field and the table name. Thank you for the help.
Apr 1 '14 #1

✓ answered by zmbd

OK,
Soap Box Out (^_^)

IMHO
It is always best practice to build your strings first.

Take for example your first construct:
Text72 = DLookup("[address]", "Customer Database", "school='" & Reports![Create Route Invoice]![School] & "'")

Let's modify this just a tad:
Expand|Select|Wrap|Line Numbers
  1. 'NOTE: The following is "air code"
  2. Dim Text72 as string
  3. Dim zCriteria as String
  4.  
  5. zCriteria = "school='" & _
  6.    Reports![Create Route Invoice]![School] & "'"
  7. '
  8. '
  9. Text72 = DLookup("[address]", "Customer Database", zCriteria) 
Now why do this?
Because we can trouble shoot:
Expand|Select|Wrap|Line Numbers
  1. 'NOTE: The following is "air code"
  2. Dim Text72 as string
  3. Dim zCriteria as String
  4.  
  5. zCriteria = "school='" & _
  6.    Reports![Create Route Invoice]![School] & "'"
  7. debug.print zCriteria
  8. '
  9. Text72 = DLookup("[address]", "Customer Database", zCriteria) 
Now by pressing <ctrl><g> the immedate window will open and we can see our resolved string for zCriteria

In my humble experiance, 90% of all dlookup errors, or indeed any function with a string criteria, occurs because the string is malformed.

Make the above changes for all of your Dlookups and see what you are actually returning to the function(s).


While were at it: [city State, Zip Code]"
is an extremely bad field name - I don't mean to be harsh; however, it's the truth in that it denotes a lack of normalization:[*]> Database Normalization and Table Structures.
and violates the token restrictions:
-alphanumeric this is very importaint to keep in mind when nameing fields, alphanumeric and preferably no spaces just underscores:
Access 2007 reserved words and symbols
AllenBrowne- Problem names and reserved words in Access

(^_^)
Ok, soap box put away now

1 1859
zmbd
5,501 Expert Mod 4TB
OK,
Soap Box Out (^_^)

IMHO
It is always best practice to build your strings first.

Take for example your first construct:
Text72 = DLookup("[address]", "Customer Database", "school='" & Reports![Create Route Invoice]![School] & "'")

Let's modify this just a tad:
Expand|Select|Wrap|Line Numbers
  1. 'NOTE: The following is "air code"
  2. Dim Text72 as string
  3. Dim zCriteria as String
  4.  
  5. zCriteria = "school='" & _
  6.    Reports![Create Route Invoice]![School] & "'"
  7. '
  8. '
  9. Text72 = DLookup("[address]", "Customer Database", zCriteria) 
Now why do this?
Because we can trouble shoot:
Expand|Select|Wrap|Line Numbers
  1. 'NOTE: The following is "air code"
  2. Dim Text72 as string
  3. Dim zCriteria as String
  4.  
  5. zCriteria = "school='" & _
  6.    Reports![Create Route Invoice]![School] & "'"
  7. debug.print zCriteria
  8. '
  9. Text72 = DLookup("[address]", "Customer Database", zCriteria) 
Now by pressing <ctrl><g> the immedate window will open and we can see our resolved string for zCriteria

In my humble experiance, 90% of all dlookup errors, or indeed any function with a string criteria, occurs because the string is malformed.

Make the above changes for all of your Dlookups and see what you are actually returning to the function(s).


While were at it: [city State, Zip Code]"
is an extremely bad field name - I don't mean to be harsh; however, it's the truth in that it denotes a lack of normalization:[*]> Database Normalization and Table Structures.
and violates the token restrictions:
-alphanumeric this is very importaint to keep in mind when nameing fields, alphanumeric and preferably no spaces just underscores:
Access 2007 reserved words and symbols
AllenBrowne- Problem names and reserved words in Access

(^_^)
Ok, soap box put away now
Apr 1 '14 #2

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

Similar topics

2
by: Mountain Man | last post by:
Hi, I'm having trouble with the foreach function. I'm using it twice inside a user defined function with two different arrays, and in the second instance it's returning the value of the first...
3
by: Jochen Zeischka | last post by:
I'm puzzled. When compiling this: template<class ValRes, class Val1, class Val2> Veld<ValRes>& mult(Veld<ValRes>& res, const Veld<Val1>& v1, const Veld<Val2>& v2) { // something return res; }...
6
by: Josh Close | last post by:
I'm having a problem with a value coming out of a loop. CREATE OR REPLACE FUNCTION funmessagespermintotal() RETURNS int8 AS ' DECLARE this_rServer record; this_rSum record; this_iSum...
28
by: Yevgen Muntyan | last post by:
Hey, Consider the following code: void func (void) { } void func2 (void) {
6
by: Kavya | last post by:
I was reading a book Test Your C++ Skills by Yashwant Kanetkar. There was a question in it Ques: Why constructors do not have return values? Ans :Constructors are called whenever an object is...
5
by: Bob | last post by:
Hi, i'm not sure to understand how a value is returned from a function. Look at this code below about a simple function that compares a value with values 1 from 5. I thought: if the passed...
6
by: rowe_newsgroups | last post by:
I just noticed this about value types and return values, and it kind of bugs me that the compiler won't treat it as an error, even with Option Strict On. Try this out: Option Strict On ...
3
Nathan H
by: Nathan H | last post by:
I don't know why I am having an issue with this, especially when I helped someone the other day. Four fields in the table tblFTPLOGIN: txtServerList txtFolder txtUID txtPWD The unbound form...
9
by: matt753 | last post by:
I'm using the Dlookup function to return the value from a table. The value is "0.05", in the table the fields format is number and decimal places set to 2. When I run the dlookup, it returns...
7
by: Vasago | last post by:
Trying to look up a value based on 2 criteria. Can't seem to debug the error thanks for your help! = Nz(DLookup("", "", "Employee='" & Forms!! & "And ='" & Date & "'"), 0)
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: 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...
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
marktang
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,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.