1

编辑经过更多研究后,我发现我不能将连续表单与未绑定表单一起使用,因为它一次只能引用一条记录。鉴于我已经改变了我的问题......

我有一个示例表单,它可以提取数据以作为中介输入到表格中。

最初表单是未绑定的,我打开到两个主要记录集的连接。我将列表框的记录集设置为其中之一,将表单记录集设置为另一个。

问题是我无法添加记录或更新现有记录。尝试键入字段几乎没有任何作用,就好像该字段被锁定(事实并非如此)。记录集的设置是 OpenKeyset 和 LockPessimistic。

表没有链接,它们来自与该项目分开的外部访问数据库,并且必须保持这种方式。我正在使用 adodb 连接来获取数据。数据与项目的分离会导致这种情况吗?

表单中的示例代码

Option Compare Database
Option Explicit

Private conn As CRobbers_Connections
Private exception As CError_Trapping
Private mClient_Translations As ADODB.Recordset
Private mUnmatched_Clients As ADODB.Recordset
Private mExcluded_Clients As ADODB.Recordset

//Construction
Private Sub Form_Open(Cancel As Integer)
    Set conn = New CRobbers_Connections
    Set exception = New CError_Trapping

    Set mClient_Translations = New ADODB.Recordset
    Set mUnmatched_Clients = New ADODB.Recordset
    Set mExcluded_Clients = New ADODB.Recordset

    mClient_Translations.Open "SELECT * FROM Client_Translation" _
                              , conn.RBRS_Conn, adOpenKeyset, adLockPessimistic

    mUnmatched_Clients.Open "SELECT DISTINCT(a.Client) as Client" _
                          & "  FROM Master_Projections a " _
                          & " WHERE Client NOT IN ( " _
                          & "       SELECT DISTINCT ClientID " _
                          & "         FROM Client_Translation);" _
                          , conn.RBRS_Conn, adOpenKeyset, adLockPessimistic

    mExcluded_Clients.Open "SELECT * FROM Clients_Excluded" _
                           , conn.RBRS_Conn, adOpenKeyset, adLockPessimistic

End Sub

//Add new record to the client translations
Private Sub cmdAddNew_Click()
    If lstUnconfirmed <> "" Then
        AddRecord
    End If
End Sub

Private Function AddRecord()
    With mClient_Translations
        .AddNew
        .Fields("ClientID") = Me.lstUnconfirmed
        .Fields("ClientAbbr") = Me.txtTmpShort
        .Fields("ClientName") = Me.txtTmpLong
        .Update
    End With
    UpdateRecords
End Function

Private Function UpdateRecords()
    Me.lstUnconfirmed.Requery
End Function

//Load events (After construction)
Private Sub Form_Load()
    Set lstUnconfirmed.Recordset = mUnmatched_Clients   //Link recordset into listbox
    Set Me.Recordset = mClient_Translations
End Sub

//Destruction method
Private Sub Form_Close()
    Set conn = Nothing
    Set exception = Nothing
    Set lstUnconfirmed.Recordset = Nothing
    Set Me.Recordset = Nothing
    Set mUnmatched_Clients = Nothing
    Set mExcluded_Clients = Nothing
    Set mClient_Translations = Nothing
End Sub
4

1 回答 1

0

我发现如果没有包含 Microsoft 访问数据库文件(外部)的提供程序和数据提供程序的连接字符串,您将无法更新/添加到记录集。如上所述,我能够提取和显示记录,但除非通过硬编码手动使用 ADO 添加/更新方法,否则我没有这些功能。

此链接具有 SQL 和 JET 连接的解决方案,可以使用这两种提供程序类型对外部数据库文件执行此操作。令人困惑的部分是在我正在使用的连接类的连接字符串中添加密码参数(用于全局文件密码)。

http://support.microsoft.com/kb/281998

于 2010-05-17T21:34:04.250 回答