PDA

View Full Version : Insert form values.



adamsm
05-11-2011, 11:06 AM
Hi anyone,

Im trying to make the following code to insert the form text box values and combo box values to the cell referenced in the code.

Private Sub cmdAdd_Click()

Dim strSentence As String
strSentence = Me.TextBox001 & " " & Me.cbofrequency1 & " " & Me.Label001.Caption & " " & Me.cbodos1
Worksheets("Crd").Range("I55") = strSentence

End Sub

But the code only inserts the textbox001 value and the label value. It does not enter the rest of the values.

What have I done wrong in here.

Any help would be kindly appreciated.

mikerickson
05-11-2011, 11:22 AM
You need to specify the property of the control that you want cocatinatied


strSentence = Me.TextBox001.Text & " " & Me.cbofrequency1.Text & " " & Me.Label001.Caption & " " & Me.cbodos1.Value

(Note that in a multi-column ListBox or ComboBox, the .Value and .Text properties may not be the same.)

adamsm
05-11-2011, 11:31 AM
Thanks for the help.

How should the code be futher modified to include a series of another combo box and text box vales to cell I56

strSentence = Me.TextBox002.Text & " " & Me.cbofrequency2.Text & " " & Me.Label002.Caption & " " & Me.cbodos2.Value
Worksheets("Crd").Range("I56") = strSentence


How should I place the above line to the code?

mikerickson
05-11-2011, 11:52 AM
Change or add the controls whose values are being concatenated.

BTW, it is probably better if each control's values were put in a separate cell. Excel works better and easier without having to parse delimited strings every time you want to work with some data. There are lots of columns available, using them is wise.

adamsm
05-11-2011, 12:37 PM
Thanks for the help and recommendation.