Update 2 fields with one combo box

  • Thread starter Thread starter LMB
  • Start date Start date
L

LMB

Hi Guys,

Access 2000. I have a combo box on a form. It shows Last and First names
from a query...they are 2 separate fields...When I select the name, I want
both fields on the table to be updated at the same time. How can I do this
using the Build Event in the control source of the properties sheet for my
combo box?

Thanks,
Linda
 
Linda,

Firstly, there's no Build event.

If I understand you correctly, you want to select a single row from the
combo box, and automatically populate two text boxes on your form with the
first and last names selected. The following assumes the following:
* The first column in the combo is a primary key;
* The second column in the combo is the first name; and
* The third column in the combo is the last name.

Private Sub cboMyCombo_AfterUpdate()
If Not IsNull(Me!cboMyCombo) Then
Me!txtFirstName = Me!cboMyCombo.Column(1)
Me!txtLastName = Me!cboMyCombo.Column(2)
End If
End Sub

If you're planning to save the value of these textboxes to the underlying
table - don't! The first column of your combo box should be the primary key
that uniquely identifies the person you selected, so you should store *that*
value - not the person's names.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

Microsoft Access 2003 VBA Programmer's Reference
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0764559036.html
 
Back
Top