Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how can i Integration all texts from a column in a form to a textBox ?

Status
Not open for further replies.

m00j

IS-IT--Management
Oct 5, 2009
3
this code can (add all text from table) to textbox in form

Set db = CurrentDb
Set rs = db.OpenRecordset("names")
For i = 1 To rs.RecordCount

text1.SetFocus
text1.Text = text1.Text & " " & rs(1)

rs.MoveNext

Next i
is it any way to ((add all text from Fields in form)) in to textbox in same form?
 
Welcome to Tek-Tips

I'm assuming this is an Access database from the code you listed.

If you really need to dig through VBA code in Access, the question is best asked in forum702.

But for now, here's how I'd do it. You don't need to create your references to your database as you are doing, just reference the various controls on the form. Or if you want to do it via the recordset, that can be done as well. If you really need to store the data that way in the table for some crazy reason, rather than just view it the way you mention, then you'd be best doing it in a standard module, not using the form code at all..

so here is how I'd do it on the form:
Code:
Private Sub Form_OnCurrent()
'Assuming to run when the current record is loaded to the form
   Dim frm as form
   Dim ctl as Control
   Dim strNewText As String 'build the text before loading to "new" text box.
   
   Set frm = Forms!MyFormName
   For Each ctl in frm.Controls
      If TypeOf ctl = vbText Then 'I forget the exact usage, you may need to find other examples to verify
        If frm.Name = "MyCombinationBox" Then
        'You don't want to copy the same control to itself
        ElseIf ctl = vbNullString Then
        'You also don't want to grab the text value if it's a nullstring
        Else 'Otherwise, you want the text, copy it to the new box.
          If strNewText = vbNullString Then
            strNewText = ctl
          Else
            strNewText = strNewText & " " & ctl
          End If
        End If
    Next ctl

    If strNewText = vbNullString Then
    Else
      MyCombinationBox = strNewText
    End If

  If ctl Is Nothing Then Else Set ctl = Nothing
  If frm Is Nothing Then Else Set frm = Nothing
End Sub

So, try the above out, edit as needed for your field/control names, and debug to fix any typos. Post back with questions.

That's how to do it on the form. If you need to do the same in the recordset instead, just build a standard module.. or an update query would do it as well, and perhaps faster.

Here's a standard module method using a recordset:
Code:
Sub ConcatonateMe()
   Dim db As DAO.Database
   Dim rs As DAO.Recordset
   
   Do While Not rs.EOF
     rs.Edit
     rs.Fields("MyCombinedField") = _
       rs.Fields("MyFirstField") & " " & _
       rs.Fields("MySecondField") & " " & _
       rs.Fields("MyThirdField") & " " & _
       rs.Fields("MyFourthField") & " " & _
     rs.Update
     rs.MoveNext
   Loop
   
   If rs Is Nothing Then rs.Close: Set rs = Nothing
   If db Is Nothing Then db.Close: Set db = Nothing
End Sub

The latter could also be done by looping through fields, just add in the line.. Dim fld AS DAO.Field and then add another loop for the fields within the recordset loop, build the string text, and then apply it to the CombinedField...

Anyway, hopefully that'll get you going if you're still working on this.


"But thanks be to God, which giveth us the victory through our Lord Jesus Christ." 1 Corinthians 15:57
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top