Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / July 2007

Tip: Looking for answers? Try searching our database.

DLookup problems

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Brad - 17 Jul 2007 16:44 GMT
Thanks for taking the time to read my question

Dim CellID as Variant 'When the DLookup works I'll change this to Integer
Dim ThePhoneNumber as String

CellID = DLookup("CellNumber", "tblCellInfo", "CellNumber = 555-555-5555")

returns Null

The value is there.

This works:
SELECT tblCellInfo.CellID, tblCellInfo.CellNumber
FROM tblCellInfo
WHERE (((tblCellInfo.CellNumber)="555-555-5555"));

I'd like to get this to work:

ThePhoneNumber = "555-555-5555"

CellID = DLookup("CellNumber", "tblCellInfo", "CellNumber = " & """" &  
ThePhoneNumber & """")

What is wrong with my DLookup??? Both make CellID = Null

Thanks,

Brad
Brad - 17 Jul 2007 17:14 GMT
I figured it out.

Single Quotes

CellID = DLookup("CellID", "tblCellInfo", "CellNumber = '" & ThePhoneNumber
& "'")

> Thanks for taking the time to read my question
>
[quoted text clipped - 24 lines]
>
> Brad
fredg - 17 Jul 2007 17:34 GMT
> Thanks for taking the time to read my question
>
[quoted text clipped - 24 lines]
>
> Brad

Well, if you already know the CellNumber is 555-555-5555 why do you
need to look it up? [CellID] = "555-555-5555"  :-(

Anyway, it seems that the field [CellNumber] is a text datatype field,
in which case the number to be looked up must be enclosed within
quotes (you did this in your Select Where clause, ...
WHERE (((tblCellInfo.CellNumber)="555-555-5555")); ... why not here?).

Since the entire where clause in the DLookUp is within quotes, you use
single quotes around the string.

CellID = DLookup("CellNumber", "tblCellInfo", "CellNumber =
'555-555-5555'")

If the actual number is unknown, but is showing on a control on the
current record on the form, then you would use:
CellID = DLookup("CellNumber", "tblCellInfo", "CellNumber = '" &
Forms!NameOfForm!![ControlOnFormName] & "'")

Signature

Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.