Selasa, 14 Mei 2019

[MS_AccessPros] Re: Populate text box base on a combo lookup

 

Hi Art


How are the two tables tblUnit and BA4602200 related?  Is it one-to-many or one-to-one?  Also, is there always a matching record in BA4602200 for every unitcode in tblUnit? If not, with what value would you want to populate your textbox?

Finally, is the user able to change the name in txtTenant, or it it locked and dependant on cmbUnit?

Depending on the answers to these questions, your RowSource query should look something like this:

SELECT tblUnit.unitid, tblUnit.unitcode, BA4602200.[Name] FROM tblUnit INNER JOIN BA4602200 ON
tblUnit.unitcode = 
BA4602200.locncode ORDER BY tblUnit.unitid;

Your combo box now has three columns, so set ColumnCount=3 and adjust the visibility of the columns by setting ColumnWidths to 0 as required.

Your [Name] value will now be in cmbUnit.Column(2).  If txtTenant is editable, then use cmbUnit_AfterUpdate to set its value:

txtTenant = cmbUnit.Column(2)

If txtTenant is locked then you don't require any code at all!  Just set its ControlSource to:

=cmbUnit.Column(2)

By the way, you should NEVER give a field (or anything else for that matter) the name of "Name".  It will only cause anguish further down the track, I can promise you!

Best wishes,
Graham [Access MVP 1996 - 2016]

__._,_.___

Posted by: graham@mandeno.com
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (2)

Have you tried the highest rated email app?
With 4.5 stars in iTunes, the Yahoo Mail app is the highest rated email app on the market. What are you waiting for? Now you can access all your inboxes (Gmail, Outlook, AOL and more) in one place. Never delete an email again with 1000GB of free cloud storage.


SPONSORED LINKS
.

__,_._,___

Tidak ada komentar:

Posting Komentar