1

我正在将 Access 2010 与 SQL Server 2008 中的链接表一起使用。我有一个使用记录集填充的表单,并且此表单中文本框的控制源设置为记录集中的一个字段。我发现虽然我可以浏览表单上的所有 16 条记录,并且表单加载正确,但我无法编辑 Notes 文本框。它需要是可编辑的。文本框的 Enabled=True 和 Locked=False。表单的 AllowEdits 属性设置为 true。查询中的所有表都有主键。那么,这是我的查询吗 - 因为它有正确的和内部的连接?所以问题是我无法在文本框中输入。

只是一点背景知识,我尝试使用查询作为此表单的记录源,但发现 Access 的自动保存功能将不完整的记录插入到我的结果表中,以及我的保存按钮事件完成的更新和插入。如果避免这种情况的唯一方法是在每次导航时询问用户他/她是否愿意保存更改,那么这对最终用户来说太令人沮丧了。所以,我不得不使用一个未绑定的表单,我使用 VBA 使用 ADO 记录集来填充它。

顺便说一句,我可以编辑 DocID 和 DocumentType 列,这是无法更改的查询字段(QCNote)

这是来自我的 Form_Open 事件的代码。我还有一个 Form_Current 事件,它禁用了不适用类别的提交按钮。

Private Sub Form_Open(Cancel As Integer)

Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset 

Set cn = CurrentProject.AccessConnection
Set rs = New ADODB.Recordset
With rs
Set .ActiveConnection = cn

DocID = [Forms]![QCDocAttributes]![DocID]

DocumentType = [Forms]![QCDocAttributes]![Document Type]

strSQL = "SELECT " & DocID & " AS DocID,'" & DocumentType & "' AS DocumentType,     QC_QCDecisionPoint.Description, QC_QCDecisionPoint.QCDecisionPointID , QC_QCResultDecisionPoint.QCNote FROM QC_QCResultDecisionPoint RIGHT JOIN ((QC_QCAttribute INNER JOIN QC_QCAttributeDecisionPointAsc ON QC_QCAttribute.QCAttributeID = QC_QCAttributeDecisionPointAsc.QCAttributeID) INNER JOIN QC_QCDecisionPoint ON QC_QCAttributeDecisionPointAsc.QCDecisionPointID = QC_QCDecisionPoint.QCDecisionPointID) ON QC_QCResultDecisionPoint.QCDecisionPointID = QC_QCDecisionPoint.QCDecisionPointID WHERE (((QC_QCAttribute.Description)= '" & [Forms]![QCDocAttributes]![AttributesDropdown] & "' ));"

.Source = strSQL
.LockType = adLockOptimistic
.CursorType = adOpenKeyset
.Open
End With
Set Me.Recordset = rs

Set rs = Nothing
Set cn = Nothing

End Sub
4

0 回答 0