2011-12-27 125 views
0

如何将所有文本从表单中的列整合到文本框中?如何将列中的所有文本以表单的形式整合到文本框中Microsoft Access VBA ms-access

这个代码可以从表添加所有文字以文本形式

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 

是它没有办法从字段中添加所有文字形式到文本框,在相同的形式?

+0

请更改您的问题。这是不可能理解的。 – 2011-12-27 20:28:08

回答

0

将您的子com1_Click替换为以下块。希望这可以帮助 。 。 。

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 
+0

先生罗米我很感激你,谢谢 – ebrahim 2011-12-30 02:21:46

0

循环显示表单中的所有控件,并将其放入一个字符串变量(或一个文本框)中。

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 
+0

先生Romi首先让我说,感谢帮助和托盘运动代码,但我没有成功,所以我跳回来帮助我,我附上示例来修改它。 http://www.mediafire.com/?4d3kykcnbetvcvy – ebrahim 2011-12-29 16:02:27

相关问题