473,508 Members | 4,628 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DLookup Help

82 New Member
Hi, I am trying to use DLookup on an after update. When the end user enters a zip code in the PracticeZip field, I want to have the County appear in the PracticeCounty field. There is a table called ZipCode that houses the zip codes and counties. If someone can help me figure out why this isn't correct, that could be great. Thanks.
Expand|Select|Wrap|Line Numbers
  1. Dim varX As Variant
  2. varX = DLookup("[County]", "ZipCode", "ZipCode = 'Form![PracticesForm]![PracticeZip]'")
  3.  
Jul 9 '13 #1
8 1339
ADezii
8,834 Recognized Expert Expert
Assuming [ZipCode] Field is a String:
Expand|Select|Wrap|Line Numbers
  1. varX = DLookup("[County]", "ZipCode", "ZipCode = '" & Forms![PracticesForm]![PracticeZip] & "'")
Jul 9 '13 #2
barbarao
82 New Member
Yes,Zip is a nvarchar. I tried what you suggested and nothing. I then moved it to the GotFocus event on the PracticeCounty field to see if the code was just in the wrong place and nothing then either. Any other thoughts?
Jul 9 '13 #3
Rabbit
12,516 Recognized Expert Moderator MVP
That can't be all the code you use to populate the control, what's the rest of it?
Jul 9 '13 #4
barbarao
82 New Member
That was all of it. What I was doing is trying to get the filed "County" to autopopulate after the end user has entered a value in the "PracticeZip" field. I have a separate table that stores Counties and Zips.
Jul 9 '13 #5
Rabbit
12,516 Recognized Expert Moderator MVP
If that's all your code, then your control isn't going to have a value. You assigned your DLookup to a variable called varX. But you never assign varX to your control.

Think of it this way, I want to give you ten dollars so I give your friend ten dollars but I don't tell your friend to pass that ten dollars on to you. How come you don't have the ten dollars?

Having said that, the only reason to do this through VBA is because you plan on storing the county. But unless your you need that county for posterity, you are breaking one of the rules of normalization by storing duplicate data.

What you should do is just put the DLookup in the control source and not store the county again in PracticeCounty. You can always get the county when needed by joining to your zip code table.
Jul 9 '13 #6
barbarao
82 New Member
I'm having a hard time following you. Sorry. I don't want to store the name of the County in the Practice Table but the county's number value. I hope that explains what I had in mind. I'm gong to keep rereading what you wrote so maybe I wil get it.
Jul 9 '13 #7
barbarao
82 New Member
Hi,

I finally understand what you wrote and have things under control here. Thanks as usual for your help.
Jul 9 '13 #8
Rabbit
12,516 Recognized Expert Moderator MVP
No problem, good luck with the rest of your project.
Jul 9 '13 #9

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

Similar topics

4
3328
by: Joe | last post by:
I have a table with an sequence (PK) and 2 fields, employee id and status id. Each employee can have multiple records in this table due to multiple status ids assigned. I have a multi-list box...
6
508
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
2264
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
1530
by: Simon | last post by:
Hi, I need some help form someone. I use my database for my online shop, so once I have entered a order onto the database I have a button that creates the Email to the customer to let them know...
1
1809
by: TerryD | last post by:
I have a form that has an unbound text field that I am using DLookup in to display the values from a Temp Table. My program calls for me pushing a button to print a report, which runs a query first...
1
1785
by: aharding | last post by:
Hello! I am using Access 2003 I have been playing with DLookup all morning and have not been successful yet. I have never used this function...and have some limited experience with code. I...
1
1346
by: alphaomega3 | last post by:
I currently have this code looking up the Vendor Name. I have just been asked to also have it lookup whether the vendor appears in a linked excel sheet tblVendorQualification and if the vendor does...
3
1369
by: MattieG | last post by:
Hi Im trying to do a DLookup on the following. I have a form field called StartDate and i want to find a price from table where Forms!Formname!StartDate BETWEEN Start2 and End2. I just cant...
15
3087
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...
8
2368
by: JDaly | last post by:
This bombs on the StPL= line. I want it to look up a string value from a table with a criterion of matching another string. In immediate mode the form evaluates correctly with ? Form!! as TEST but...
0
7393
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...
0
7502
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...
0
5635
agi2029
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,...
1
5057
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3206
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3191
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1565
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
426
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.