Appending a field with data using combo box

B

b_a_redman

I have a field called 'counties served'. On my form i have a combo box that
stores county values, this was done through the wizard where i entered in the
values i want it to show. What i want to be able to do is select a county,
then click on a button, which will add it to the field. Then i can select
another value, and that value also be inserted into the field aswell. So for
example, i have selected Sussex from the combo box, i click add which moves
it into the field. I then select Surrey and click add, this adds the data to
the record, so that field would now read 'Sussex, Surrey'. Each county must
be seperated by a comma. I have no knowledge of access or vba, so can someone
explain to me how to do this and provide me with the code if possible.

Field Name - Counties Served
Combobox name - Combo1
Buttonname - Button1
 
M

Mr. B

I have a field called 'counties served'. On my form i have a combo box that
stores county values, this was done through the wizard where i entered in the
values i want it to show. What i want to be able to do is select a county,
then click on a button, which will add it to the field. Then i can select
another value, and that value also be inserted into the field aswell. So for
example, i have selected Sussex from the combo box, i click add which moves
it into the field. I then select Surrey and click add, this adds the data to
the record, so that field would now read 'Sussex, Surrey'. Each county must
be seperated by a comma. I have no knowledge of access or vba, so can someone
explain to me how to do this and provide me with the code if possible.

Field Name - Counties Served
Combobox name - Combo1
Buttonname - Button1

First, attempting to store multiple values in one field is not
considered to be correct. You should really consider normalizing your
database.

However, with that said, you can place the following code in the After
Update event of your combo box:

If Not IsNull(Me.cboCountries) Then
If Me.Text0 > "" Then
Me.Text0 = Me.Text0 & ", " & Me.cboCountries
Else
Me.Text0 = Me.cboCountries
End If
End If

Just replace the "cboCountries" witht he actual name of your combo box
and the "Text0" with the actual name of your Text box.

HTH

Mr B
 
K

Klatuu

This is not the correct way to do this. For a correctly normalized database,
you should have a table that would be a child table to the table where you
are wanting to store multiple values. It needs the following fields:

tblCountiesServed
[COUNTY_SERVED_PK], Autonumber, the Primary key of this record
[MAIN_TABLE_FK] Long, the primary key of the main table
[COUNTY_FK] Long, the primary key of a county served.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top