![](/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.