Move down one line in a textbox

  • Thread starter Thread starter jlgandara
  • Start date Start date
J

jlgandara

I have a combobox that populates a textBox. That is working fine. What
I can't figure out is that when I want to add another record to the
same textBox, coming from the same comboBox, I'm not able to do so. I
want to know if there is a way to tell VBA to put that new record under
the previous one. Here is the code I have so far.

Private Sub Command130_Click()
Dim aov100 As String
aov100 = Me.Combo126.Value
Me.txtTeam.Value = aov100
Me.teamMem.Value = aov100
Me.Combo126.Value = ""
End Sub

teamMem is the field in the table and it's data type is set to text.

Thanks
 
You are either mixing terms or do not understand textBox and comboBox
operation.

A textBox is either bound or unbound to a table field directly or by way of
a query. It CAN NOT have more than one record. It can contain data from
more than one field by concatenating in the query.

Or did I misunderstand what you said?
 
I'm sorry I did mix the terms. When I said record I actually meant
data. The textBox is bounded to a field in a table. I have a comboBox
with a the data from another table. And I have a button that moves
whatever is selected in that cmbox to the textbox. Every time I select
something from the cmbox and click the button, the data that was
already in the textbox is replaced by the new data I selected. This is
an example of what I want the button to do in the textbox.
 
Perhaps this:

Private Sub Command130_Click()
Dim aov100 As String
aov100 = Me.txtTeam.Value
If Len(aov100 & "") > 0 Then aov100 = aov100 & vbCrLf
aov100 = aov100 & Me.Combo126.Value
Me.txtTeam.Value = aov100
Me.teamMem.Value = aov100
Me.Combo126.Value = ""
End Sub
 
Thanks Ken. Now how do I get that code to work when the txtBox is
empty. I get the "Invalid use of Null" Message if the txtBox is already
empty. The code only works if the txtBox has something on it already.
Thanks again
 
This should handle that:

Private Sub Command130_Click()
Dim aov100 As String
aov100 = Me.txtTeam.Value & ""
If Len(aov100 & "") > 0 Then aov100 = aov100 & vbCrLf
aov100 = aov100 & Me.Combo126.Value
Me.txtTeam.Value = aov100
Me.teamMem.Value = aov100
Me.Combo126.Value = ""
End Sub
 
Slight revision to remove redundant code:

Private Sub Command130_Click()
Dim aov100 As String
aov100 = Me.txtTeam.Value & ""
If Len(aov100) > 0 Then aov100 = aov100 & vbCrLf
aov100 = aov100 & Me.Combo126.Value
Me.txtTeam.Value = aov100
Me.teamMem.Value = aov100
Me.Combo126.Value = ""
End Sub
 

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

Back
Top