Solved

Text Fields auto entry

Posted on 2004-09-10
13
196 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
  • 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

759 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now