简体   繁体   中英

how can i Integration all texts from a column in a form to a textBox Microsoft Access VBA ms-access

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

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?

Loop through all the controls in the form and put it in a string variable (or a textbox).

Dim cControl As Control
Dim sNames As String
sNames = ""
For Each cControl In Me.Controls
    If TypeName(cControl) = "TextBox" Then
        sNames = sNames + " " + cControl
    End If
Next cControl

Replace your sub com1_Click with following block. Hope this helps . . .

Private Sub com1_Click()
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim strNames As String
    Dim strSQL As String

    ' Following line gets the query of the form
    strSQL = Me.RecordSource
    ' Alternatively, you can replace this line with your own select query
    ' For eg.
    ' strSQL = "Select * from Table1 Where [_ID] In (1,2)"


    Set db = CurrentDb
    Set rs = db.OpenRecordset(strSQL)

    strNames = ""

    'Following loop is for going through all the records
    While Not rs.EOF
        'Following line is for collecting values of Name1 Field of your table
        strNames = strNames & " " & rs("Name1")
        rs.MoveNext
    Wend

    ' Populating the textbox with values collected from your table
    text3 = Trim(strNames)

    ' Final cleanup
    rs.Close
    Set rs = Nothing
    Set db = Nothing
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM