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. - Private Sub Report_Load()
-
Text72 = DLookup("[address]", "Customer Database", "school='" & Reports![Create Route Invoice]![School] & "'")
-
Text75 = DLookup("[city State, Zip Code]", "Customer Database", "school='" & Reports![Create Route Invoice]![School] & "'")
-
Text93 = DLookup("[PRP]", "Route Pricing per School", "school='" & Reports![Create Route Invoice]![School] & "'")
-
[Excess time per Hour] = DLookup("[ETPH]", "Route Pricing per School", "School='" & Reports![Create Route Invoice]![School] & "'")
-
[Excess Mileage Rate per Mile] = DLookup("[EMRPM]", "Route Pricing per School", "School='" & Reports![Create Route Invoice]![School] & "'")
-
'[number of trips]
-
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.
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: - 'NOTE: The following is "air code"
-
Dim Text72 as string
-
Dim zCriteria as String
-
-
zCriteria = "school='" & _
-
Reports![Create Route Invoice]![School] & "'"
-
'
-
'
-
Text72 = DLookup("[address]", "Customer Database", zCriteria)
Now why do this?
Because we can trouble shoot: - 'NOTE: The following is "air code"
-
Dim Text72 as string
-
Dim zCriteria as String
-
-
zCriteria = "school='" & _
-
Reports![Create Route Invoice]![School] & "'"
-
debug.print zCriteria
-
'
-
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: - 'NOTE: The following is "air code"
-
Dim Text72 as string
-
Dim zCriteria as String
-
-
zCriteria = "school='" & _
-
Reports![Create Route Invoice]![School] & "'"
-
'
-
'
-
Text72 = DLookup("[address]", "Customer Database", zCriteria)
Now why do this?
Because we can trouble shoot: - 'NOTE: The following is "air code"
-
Dim Text72 as string
-
Dim zCriteria as String
-
-
zCriteria = "school='" & _
-
Reports![Create Route Invoice]![School] & "'"
-
debug.print zCriteria
-
'
-
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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;
}...
|
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...
|
by: Yevgen Muntyan |
last post by:
Hey,
Consider the following code:
void func (void)
{
}
void func2 (void)
{
|
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...
|
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...
|
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
...
|
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...
|
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...
|
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)
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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: 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: 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: 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...
|
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...
|
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,...
| |