Log in

View Full Version : [SOLVED:] Checkbox combining two combobox text results into a third combobox



DavG63
01-28-2016, 09:13 AM
I have a userform at the moment with two comboboxes for (i) address and (i) zip code.

ComboBox1 is the address - "1 Street Name, Town"
ComboBox2 is the zip code - "77048"

I have to keep them apart as they appear at different points throughout the document sometimes together and sometimes not.

I was hoping to be able to put a checkbox beside the two comboboxes which when checked would copy the values of both ComboBoxes into another ComboBox for the billing address.

Can anyone help me work out how to take the values of ComboBox1 and ComboBox2 and combine them to display in ComboBox3 if CheckBox1 is checked so that it reads "1 Street Name, Town, 77048"? i.e.


If Me.CheckBox1.Value = True Then
Me.CheckBox3.Value = Me.CheckBox1 + Me.CheckBox2

Obviously this won't work with text and it also has to put a comma in before the zip code and then leave a space for the formatting to work properly, but I'm a little stuck as to how to do it.

Any assistance would be gratefully received.

Thanks

Peter Mole
01-28-2016, 06:38 PM
Haven't checked this but it should work. I think you are better to throw the result to a text box rather than a combo box. If you need the billing address as a combo list you might have to firstly generate the list, wrap it as an array and then feed it back into the combo box;



' This is assuming that there are values selected in the combo boxes, I would assume you would validate this prior.
Dim billingAddress as String

billingAddress = ComboBox1.Text & ", " & ComboBox2.Text

If Me.CheckBox1.Value = True Then

TextBox3.Text = billingAddress
Else
TextBox3.Text = vbNullString
End If

gmayor
01-28-2016, 11:49 PM
Rather than use two combo boxes, use a single combo box with two columns, the first column with the address, the second with the zip.
You then only need one selection and the check box is redundant.
You can then use the address directly from the combo box into your document either as the combined result of the two columns or just the one as required

e.g.

strAddress = Me.ComboBox1.Column(0) & Chr(44) & Chr(32) & Me.ComboBox1.Column(1)
strZip = Me.ComboBox1.Column(1)

Then write strAddress or StrZip to the document as required.

DavG63
01-29-2016, 02:06 AM
Thanks both for your help, I've got this working now.

I also had no idea you could split a ComboBox into columns!

Dav