【问题标题】:Continuous Form, how to add/update records with external connection连续表格,如何通过外部连接添加/更新记录
【发布时间】:2011-02-18 04:56:36
【问题描述】:

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

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

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

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

【问题讨论】:

  • Mohgeroth,我认为您的问题有点令人困惑,也不是很清楚。我“认为”您要问的是如何在不使用数据绑定的情况下使用 Access 连续表单?这就是你要问的吗?看看您是否可以将您的问题重新表述为一句话。也许改变你的标题。赛斯

标签: ms-access adodb continuous-forms


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 2016-08-20
    • 2015-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-05
    • 1970-01-01
    • 2020-05-13
    相关资源
    最近更新 更多