access : 用 VBA 单独填充文本框

access : populate textbox separately with VBA

在 Acces 中,我有一个带有独立文本框的连续表单。 我尝试为查询结果中找到的每条记录使用 vba 来填充它,但这会用相同的值填充所有文本框。

这是我的表格

Private Sub Form_Open(Cancel As Integer)
Dim WO As String
WO = Forms![Maintenance input formulaire]![Maintenance input sous formulaire].Form![WONumber]

query = "select comment from SystemAircraftStatus where SystemID = " + CStr(Me.SystemID) + " and WO = '" + WO + "';"
Debug.Print (query)

Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset(query)

If Not (rs.EOF And rs.BOF) Then
    rs.MoveFirst
    Me.Texte54.Value = rs.Fields("comment") 'PROBLEME : est appliqué a tous les enregistrements
End If

End Sub

这是VBA代码,只有第一个结果("autre")有评论。

是否有单独填充每个文本框的解决方案?

之所以用一个值填充所有的文本框:它是一个连续的

表单和文本框 未绑定

文本框必须绑定到表单记录中的值才能显示不同的值。

我建议您使用记录集对象将文本框绑定到表单记录集中的值。像这样:

Sub Form_Open(Cancel As Integer)
dim qry as string

qry = _
"select WO, comment from SystemAircraftStatus where SystemID = " + CStr(Me.SystemID) + " and WO = '" + WO + "';"

me.recordset = qry

End Sub

您需要在 SQL 查询记录集对象时直接 select 这两个值。

然后使用文本框的属性将其绑定到查询中的值。

此致