![](/img/trans.png)
[英]VBA: How go I get the total width from all controls in an MS-Access form?
[英]how can i Integration all texts from a column in a form to a textBox Microsoft Access VBA ms-access
如何将表单中的所有文本集成到textBox中?
此代码可以将表格中的所有文本添加到表格中
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
有什么办法可以将表单中的“ 字段”中的所有文本添加到同一表单的文本框中?
循环浏览表单中的所有控件,并将其放入字符串变量(或文本框)中。
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
将您的子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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.