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

DLookup in VBA

Can anyone tell me why this VBA returns a null value when the source
table doesn't have one?

I have a table called 'zTerms' with fields 'TermID', 'Term',
'TermStartDate' and 'TermEndDate'

I need to return the TermID when the IncidentDate shown on the form is
between the the two dates.

I have tried the following methods all to no avail.

stTermID = DLookup("[TermID]", "zTerms", "[TermStartDate] < " &
stIncidentDate & " And [TermEndDate]>" & stIncidentDate)

stTermID = DLookup("[TermID]", "zTerms", "[TermStartDate] < " &
stIncidentDate & " And [TermEndDate]>#" & stIncidentDate & "#")

Help!!!
Nov 13 '05 #1
1 3126
Dates have to be delimited with # symbols, and must be in mm/dd/yyyy format,
regardless of what your Regional Settings are. (Okay, that's not strictly
true: you can use any unambiguous format, such as yyyy-mm-dd or dd mmm yyyy.
The point is, you cannot use dd/mm/yyyy in a DLookup even if that's what
your Regional Settings are)

I tend to use the Format statement to do both of the points above:

stTermID = DLookup("[TermID]", "zTerms", "[TermStartDate] < " &
Format(stIncidentDate, "\#mm\/dd\/yyyy\#") & " And [TermEndDate]>" &
Format(stIncidentDate "\#mm\/dd\/yyyy\#"))

If that still doesn't work, are you certain there is a value within the
range? Do stIncidentDate also include time?
--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

"Colin Mardell" <co***********@btopenworld.com> wrote in message
news:e9*************************@posting.google.co m...
Can anyone tell me why this VBA returns a null value when the source
table doesn't have one?

I have a table called 'zTerms' with fields 'TermID', 'Term',
'TermStartDate' and 'TermEndDate'

I need to return the TermID when the IncidentDate shown on the form is
between the the two dates.

I have tried the following methods all to no avail.

stTermID = DLookup("[TermID]", "zTerms", "[TermStartDate] < " &
stIncidentDate & " And [TermEndDate]>" & stIncidentDate)

stTermID = DLookup("[TermID]", "zTerms", "[TermStartDate] < " &
stIncidentDate & " And [TermEndDate]>#" & stIncidentDate & "#")

Help!!!

Nov 13 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

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...
6
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...
5
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...
4
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...
2
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...
8
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 ...
11
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...
2
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...
9
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...
15
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...
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
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...

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.