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

How do I populate a text box based on the data in another text box?

I have a form that has a region code on it. That region code is based on the zip code. What code would I use to have the program lookup the region code once the zip code has been entered. I already have a table that has the zip codes broken down into their regions.
Sep 11 '09 #1

✓ answered by ajalwaysus

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub txtHomeZip_AfterUpdate()
  3.      me.REGION_CD.Value = DLookUp ("Region Number", "REGION BREAKDOWN BY ZIP CODE", "Zip_Code = " & me.txtHOME_ZIP.Value)
  4. End Sub
  5.  
Try this, you didn't include the "txt" in the "me.HOME_ZIP.Value", and if this doesn't work give me the error message.

Also, are you wanting to save this field, or is it just for displaying? I ask, because if you are only doing it for displaying, there may be a more efficient way of doing this that I have in mind.

-AJ

10 3228
ajalwaysus
266 Expert 100+
I would write some VBA code on the AfterUpdate event of the Zipcode, that would do a DLookUp based on the ZipCode, then assigns a value to the region field.

Example:
Expand|Select|Wrap|Line Numbers
  1. Private Sub ZIPCODE_AfterUpdate()
  2.      me.Region.Value = DLookUp("REGION", "[TABLE1]", "ZIPCODE = " me.ZipCode.Value)
  3. End Sub
  4.  
-AJ
Sep 11 '09 #2
Here's the code I've got but it doesn't like the last me.HOME_ZIP.Value. What did I do wrong?
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtHomeZip_AfterUpdate()
  2.     me.REGION_CD.Value = DLookUp ("Region Number", "[REGION BREAKDOWN BY ZIP CODE]", "Zip_Code = " me.HOME_ZIP.Value)
Sep 11 '09 #3
ajalwaysus
266 Expert 100+
Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub txtHomeZip_AfterUpdate()
  3.      me.REGION_CD.Value = DLookUp ("Region Number", "REGION BREAKDOWN BY ZIP CODE", "Zip_Code = " & me.txtHOME_ZIP.Value)
  4. End Sub
  5.  
Try this, you didn't include the "txt" in the "me.HOME_ZIP.Value", and if this doesn't work give me the error message.

Also, are you wanting to save this field, or is it just for displaying? I ask, because if you are only doing it for displaying, there may be a more efficient way of doing this that I have in mind.

-AJ
Sep 11 '09 #4
I got it to accept the statement when I added a comma after the last set of closing quotes and before the Me.txtHomeZip.Value (see code)
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtHomeZip_AfterUpdate()
  2.     Me.REGION_CD.Value = DLookup("Region Number", "[REGION BREAKDOWN BY ZIP CODE]", "Zip_Code = ", Me.txtHomeZip.Value)
  3. End Sub
I then tried to run it, but I am getting a compile error of Wrong number of arguments or invalid property assignment. Could I maybe be referring to the wrong names? The REGION_CD is the name of the text box on the form that I want the region code to show after the zip is entered. The "Region Number" is the column in the REGION BREAKDOWN BY ZIP CODE table that is the region code. The Zip_Code is a column in the REGION BREAKDOWN BY ZIP CODE table and the txtHomeZip is the text box in the form where the zip code is initially typed. I'm sure I've thoroughly confused you now, so just let me know if you need further explanation.
Sep 11 '09 #5
missinglinq
3,532 Expert 2GB
If ZipCode is defined as a Number Datatype:
Expand|Select|Wrap|Line Numbers
  1. me.Region.Value = DLookUp("REGION", "[TABLE1]", "[ZIPCODE] = " & me.ZipCode.Value)
If ZipCode is defined as Text Datatype:
Expand|Select|Wrap|Line Numbers
  1. me.Region.Value = DLookUp("REGION", "[TABLE1]", "[ZIPCODE] = '" & me.ZipCode.Value & "'")
You have to be sure, of course, that all the object names are the same as your actual names.

Linq ;0)>
Sep 11 '09 #6
ajalwaysus
266 Expert 100+
Your compile error is because of your extra comma, you are now passing 4 arguments to a function (DLookUp) that only uses 3. Every comma you use adds another argument.

I found an error in my code in Post #4 and then corrected it, please try it again, and if it does not work, give me the error.

-AJ
Sep 11 '09 #7
NeoPa
32,556 Expert Mod 16PB
See Quotes (') and Double-Quotes (") - Where and When to use them. Assuming the ZIP code is alphanumeric you would need to surround the value in quotes (').
Try :
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtHomeZip_AfterUpdate()
  2.     Me.REGION_CD = DLookup("[Region Number]", _
  3.                             "[REGION BREAKDOWN BY ZIP CODE]", _
  4.                             "Zip_Code = '" & Me.txtHomeZip & "'")
  5. End Sub
Sep 11 '09 #8
ajalwaysus
266 Expert 100+
Keep in mind what NeoPa and missinglinq are saying, but in regards to your compile error, make sure to read my post #7.

Don't mean to override you NeoPa, but the compile error stateemk is having still exists in your code. I point it out in post #7. =)

-AJ
Sep 11 '09 #9
NeoPa
32,556 Expert Mod 16PB
No. You're absolutely right AJ. I didn't pay enough attention.

I have fixed my earlier post in place.
Sep 11 '09 #10
I think it's working the way I want it. I'm still doing some testing. Thanks for all your help.
Sep 14 '09 #11

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

Similar topics

11
by: alex | last post by:
Hi, I am looking for a way to populate an HTML table from an external local text file which looks like this: DATE/TIME LAT. LON. DEPTH. ML....
4
by: godber | last post by:
I need to populate text boxes for instance with employee information using their unique employee works number selected from a combo box. Can anyone help, I am told thru visual basic this can be...
7
by: Sharon | last post by:
I have successfully loaded a DataSet object with a XML schema (XSD). Now I wish to populate the tables that was created in the DataSet. I have an XML file/string that contain all the needed data...
14
by: Barney | last post by:
How can I populate a textbox from a dataview? I have a dataset i'm filtering on and i want to populate several textboxes based on that filter. How can i get that to work? I've tried: ...
5
by: Arpan | last post by:
In order to populate any server control with data dynamically, is it ALWAYS NECESSARY to either BIND the DataSource to that server control or call the DataBind method of that server control? For...
1
by: vj | last post by:
How i can populate all fileds dynamically in jsp page based on contents found in xml file? I have written jsp servlets and java class file. i transferred automatic data from jsp to servlet then to...
0
by: vijendra | last post by:
How i can populate all fileds dynamically in jsp page based on contents found in xml file?I have written jsp servlets and java class file. i transferred automatic data from jsp to servlet then to...
0
by: jm | last post by:
I have a Gridview with a LinkButton. The button has text from my database. It is not the datakey of the database, just free form text. I want to populate another gridview based upon the data in...
4
by: whamo | last post by:
I have the need to populate a field based on the selection in a combo box. Starting out simple. (2) tables tbl_OSE_Info and tbl_Input; tbl_OSE_Info has three fields: Key, OSE_Name and OSE_Wt...
2
by: Ronald | last post by:
I hope somebody can help. I can't get into the specifics of my project, but I'll try to create a simple example: tblVehicle * VIN (text box) * Make (text box) * Model (text box) frmRepair
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.