Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Text Fields auto entry

Posted on 2004-09-10
13
Medium Priority
?
247 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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 2000 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

721 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