Solved

Text Fields auto entry

Posted on 2004-09-10
13
215 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sql statement - 9 26
Combobox row source 2 21
SQL Group on First occurrence 9 26
access query to sql server 3 21
When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

803 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