Solved

Text Fields auto entry

Posted on 2004-09-10
13
236 Views
Last Modified: 2010-08-05
I have a text box on a form, named BldgNum (Meaning building Number)  when I type a number is this field the next text box (BldgName) automatically dispalys the building name.  How can I accoplish this?
0
Comment
Question by:antonyeo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 4
  • +1
13 Comments
 
LVL 27

Expert Comment

by:jjafferr
ID: 12027997
Hi antonyeo,

On Lost Focus of BldgNum have this code:

me.BldgName=dlookup("[BldgName]","TableName","[BldgNum]=Forms![YourFormName]![BldgNum]")

I hope this helps.

jaffer
0
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 12028022
I would recommend using a combo box to achieve this. That also has the advantage that you can limit the user to only typing in existing building numbers. Instead of the textbox, create a combo box with this kind of row source:

SELECT BldgNum, BldgName FROM MyTable

Set the second text box's control source to:
=Form!MyComboBox.Column(1)

That should do what you need.
0
 

Author Comment

by:antonyeo
ID: 12028097
I should mention that there are 500 building numbers...

At some place shouldn't I have to list the numbers and names??
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 27

Expert Comment

by:jjafferr
ID: 12028123
You should be having both of them in a Table
0
 

Author Comment

by:antonyeo
ID: 12028568
Ok I started over the field names have change bNum (building Number), and Organization (is the name).  So i created a text field in the table (lookup).  I used 2 colums, column 1 has the numbers and two has the names.  I inserted the bNum field in the form and set the control source to bNum.  The organization field is slso in the form and its control source is set to =[Form]!bNum.Column(2).  But I get nothing in the Organization field when using the drop down box bNum on the form.
0
 
LVL 26

Expert Comment

by:dannywareham
ID: 12028592
I'd also recommend a combobox.

However, if the text box is the way forward, you can use code to return a message if the building number is not found
Something like:

Private Sub BldgName_AfterUpdate()
On error goto errtrap

Dim tempvalue as string
tempvalue = dlookup("[BldgName]","TableName","[BldgNum]=Forms![YourFormName]![BldgNum]")

If len(tempvalue)<=0 then    'check the length of the look up value
msgbox ("Name not found")
me.BldgName.setfocus
else
me.BldgName=tempvalue
end if
exit sub

errtrap:
msgbox ("Name not found")
me.BldgName.setfocus

end sub
0
 
LVL 27

Expert Comment

by:jjafferr
ID: 12028641
antonyeo
You have mixed up between the solutions, so you used part of my code and part of Shane, well, it doesn't work this way.

dannywareham just posted a more expanded version of my solution, oterwise you can use what I gave you:

On Lost Focus of BldgNum have this code:

me.BldgName=dlookup("[BldgName]","TableName","[BldgNum]=Forms![YourFormName]![BldgNum]")

jaffer
0
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 12028642
It needs to be column(1) not column(2) - column numbers start from 0.
0
 
LVL 27

Expert Comment

by:jjafferr
ID: 12028675
Shane
You have to guide antonyeo in how to accomplish making a combobox with 2 columns, before he can get the value out of it.

jaffer
0
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 12028698
jjaffer - read his post above. I am assuming he has already created the combo box since he already mentions two columns.
0
 

Author Comment

by:antonyeo
ID: 12029076
OK I placed: SELECT BldgNum, BldgName FROM thetable (names changed to reflect the names I use) inside the row source properties box of the BldgNum on the form.

I then placed =theform!BldgNum.Column(1) inside the control source properties box of the BldgName field on the form.

I get #Name in the BldgName field on the form.  Perhaps I've changed the name incorrectly on the formula.  Taking the code you gave I changed them as follows:

SELECT BldgNum, BldgName FROM MyTable  =  SELECT BldgNum, BldgName FROM thetable

and

=Form!MyComboBox.Column(1)  =  =Form!BldgNum.Column(1)



0
 
LVL 41

Accepted Solution

by:
shanesuebsahakarn earned 500 total points
ID: 12029122
That's right, but you need to make sure that the name of the combo box is called BldgNum as well. Click on the combo and bring up the Properties window. Check what the Name property is on the Other page. Use that instead of BldgNum in the control source.
0
 

Author Comment

by:antonyeo
ID: 12048931
Ok finally!!! I got it thanks Shane!  I see I can copy and paste it to different database too.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question