Solved

Text Fields auto entry

Posted on 2004-09-10
13
243 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
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…

617 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