473,395 Members | 1,341 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 check

Abhean
32
Need some help/pointer. I am attempting to search a table/field to see if it matches a field in a form.

This is not working for me. I am just looking to hard, but reaching out.

Expand|Select|Wrap|Line Numbers
  1. If Me.Txt_field = DLookup("[field]", "Table", Preset_variable) Then
  2.    'found it
  3. Else
  4.    'didnt find it
  5.  
  6. End If
Jul 23 '20 #1

✓ answered by cactusdata

Try this modification:

Expand|Select|Wrap|Line Numbers
  1. If FullEmail = DLookup("[LTDEmail]", "LTDEmail", "[LTDEmail] = '" & Me!LTDEmail.Value & "'") Then

7 2917
NeoPa
32,556 Expert Mod 16PB
The basic construct of the code seems fine. We don't see what data you're working with, nor what you mean by it failing, so that's as far as we can go for now.

What is contained in Preset_variable?
Jul 23 '20 #2
jimatqsi
1,271 Expert 1GB
Let's double-check a few things. What is the name of the table you are searching? What is the name of the field in the table? "Preset_variable" doesn't look like a comparison test.
Jul 24 '20 #3
MikeTheBike
639 Expert 512MB
Hi All

Long time since I posted here!

Not withstanding the previous replies, may I suggest this or similar may help

Expand|Select|Wrap|Line Numbers
  1. If DCount("[field]", "Table", "[field] = " & Me.Txt_field) >= 1 Then
  2.    'found it
  3. Else
  4.    'didnt find it
  5. End If
As you just need to know if it exist (at least once), I would use DCount() as DLookUp() will return Null if nothing is found. This of course can ne worked round if absolutely necessary.

Above assumes Txt_field is numeric.

I could be totally wrong, but just a thought.
Jul 24 '20 #4
Abhean
32
Sorry for the delay. I am attempting to check a table to see if an email is already in the table.

It appears that the code is always giving a true response.

And please do not blast me for the naming. I know. :)

Expand|Select|Wrap|Line Numbers
  1. Dim FullEmail As String
  2. Dim EMName As String
  3.  
  4. 'Prepare the email, Strip first initial from first name
  5.      initial = Left(LTDLastName, 1)
  6.     'Combine first name w/ last name initial
  7.      EMName = [FirstName] & [initial]
  8.     'Add @labtechdiagnostics after combination
  9.     Me.LTDEmail.Value = [EMName] & "@LabtechDiagnostics.net"
  10.     'Check Email
  11.     'set full email for lookup
  12.     FullEmail = Me.LTDEmail
  13.         If FullEmail = DLookup("[LTDEmail]", "LTDEmail", Me.LTDEmail) Then
  14.                 MsgBox "This Email has already been used. Please modify this one." _
  15.                        & vbCr & vbCr & "Please modify Email.", vbInformation, "Duplicate information"
  16.                  Me.LTDEmail.SetFocus
  17.             Else
  18.                 MsgBox "Did not Find that Email"
  19.  
  20.         End If
  21.  
  22.  
Jul 24 '20 #5
cactusdata
214 Expert 128KB
Try this modification:

Expand|Select|Wrap|Line Numbers
  1. If FullEmail = DLookup("[LTDEmail]", "LTDEmail", "[LTDEmail] = '" & Me!LTDEmail.Value & "'") Then
Jul 24 '20 #6
Abhean
32
Thanks @cactusdata
I don't think Ill ever be able to figure out the damnable quotes.
Works like a dream
Jul 24 '20 #7
NeoPa
32,556 Expert Mod 16PB
Abhean:
I don't think Ill ever be able to figure out the damnable quotes.
See if Quotes (') and Double-Quotes (") - Where and When to use them helps.
Abhean:
And please do not blast me for the naming. I know. :)
I won't. Please understand though, that if/when we do draw your attention to things like naming and code indenting it's because we understand how getting it wrong can lead to extra levels of confusion and difficulty for you. If something's simple then you won't struggle so much with it. Naming and code indentation help you to read what is there and understand it more easily. Their benefits are not restricted to that but they certainly do go to make your life easier, quite apart from ours when we want to help you.
Jul 25 '20 #8

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

Similar topics

2
by: sherah | last post by:
I am trying to create a procedure that has values are entered into a table that based on the value entered will programatically decide weather or not the Yes/No should be checked. I am trying to...
6
by: Don Sealer | last post by:
I've written this expression for a DLookup function. It works almost alright. What I'm trying to do is type in a description and the ID field (number) populates automatically. It works almost as...
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...
2
by: c.kurutz | last post by:
Hello everyone. I have a problem with looking up pricing. Here is what I have so far: TABLES tblItems: itemid itemdescription itemunit (each, roll, square foot) location1price
2
by: boyleyc | last post by:
Hi all the following code works perfectly well. Basically it populates a series of check boxes on my form, depending on whether dlookup finds an associated record. The problem i have is that...
2
by: tasawer | last post by:
I am using DLOOKUP to bring up the value of VAT rate applicable in a particular date period. but it is not bringing expected values. Can someone help me resolve the issue. Thx I have a table:...
7
by: WannabePrgmr | last post by:
What I am trying to do is on the click event of "Command167", run a Dlookup on the number that was just typed into "cboMoveTo1" and find the value located in the table "tblName" in the "Open/Closed"...
1
by: toadmaster | last post by:
I am trying to use the DLookup function to check a table to see if a user exist in there; if not refuse them access. The following is the code I am using but it seems to just pop up the "Error...
9
by: soule | last post by:
In my .accdb, DAO Db, I'm trying to use an AfterUpdate or OnLostFocus event procedure in a class module to populate a date on two tables. My form control is bound to the "MovieCodeSendDate" field...
6
by: Rinis | last post by:
Edit #1 - I'm Using access 2010 with an access desktop database (.accdb). hopefully i'm referring to that correctly. I'm working on a makeshift timeclock via VBA and access and I was never the best...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.