Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dlookup for string 2

Status
Not open for further replies.

hoofit

Technical User
Nov 20, 2005
343
US
Good morning,

In my code I'm looking for whether or not a string exists using the Dlookup function. I've declared the variable as a string but it seems like an error will occur in this instance if there is nothing found because of the null to zero. Should I change the code, leave it or is there something else I am not seeing. I could use a second set of eyes if someone would like to jump in.


Dim doesMeter4Exist as String

doesMeter4Exist = Nz(DLookup("unitOfMeasure", "TblrunningMeter", "meterID = 4 AND unitID = forms!frm_mainUnit!unitID"))
If Not doesMeter4Exist = "" Then ....blah blah blah

Thank you
 
Perhaps this ?
Dim doesMeter4Exist As Variant

doesMeter4Exist = DLookup("unitOfMeasure", "TblrunningMeter", "meterID=4 AND unitID=" & Me!unitID)
If Trim(doesMeter4Exist & "") = "" Then

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi PHV,
OK so you suggest removing the "NZ" which clears up the "number zero" concern. Could you clarify what the trim function is doing?

Thank you kindly
 
Trim just gets rid of leading and trailing spaces.
 
Great, I'll give it a shot. Thank you for your time this am!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top