Ms access 连续表单,如何使用外部连接添加/更新记录

Ms access 连续表单,如何使用外部连接添加/更新记录,ms-access,adodb,continuous-forms,Ms Access,Adodb,Continuous Forms,编辑经过进一步的研究,我发现我不能将连续表单与未绑定表单一起使用,因为它一次只能引用一条记录。考虑到我已经改变了我的问题 我有一个示例表单,它提取数据作为中介输入到表中 最初,表单是未绑定的,我打开了到两个主记录集的连接。我将listbox的记录集设置为其中一个,将forms记录集设置为另一个 问题是我无法添加记录或更新现有记录。尝试键入字段不会产生任何效果,就像字段被锁定一样(事实并非如此)。记录集的设置为OpenKeyset和Lock悲观 表没有链接,它们来自与此项目分离的外部access数

编辑经过进一步的研究,我发现我不能将连续表单与未绑定表单一起使用,因为它一次只能引用一条记录。考虑到我已经改变了我的问题

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

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

问题是我无法添加记录或更新现有记录。尝试键入字段不会产生任何效果,就像字段被锁定一样(事实并非如此)。记录集的设置为OpenKeyset和Lock悲观

表没有链接,它们来自与此项目分离的外部access数据库,并且必须保持这种方式。我正在使用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
选项比较数据库
选项显式
作为CRobbers_连接的专用连接
作为CError_陷阱的私有例外
私有mClient_翻译为ADODB.Recordset
作为ADODB.Recordset的私有munu客户端
私有mExcluded_客户端作为ADODB.Recordset
//建筑
私有子表单_打开(取消为整数)
设置连接=新的交叉连接
设置异常=新的错误捕获
Set mClient\u Translations=New ADODB.Recordset
Set mUnmatched_Clients=New ADODB.Recordset
Set mExcluded_Clients=New ADODB.Recordset
mClient_Translations.Open“选择*来自客户端_Translation”_
,conn.RBRS_conn,adOpenKeyset,adlock悲观
mUnmatched_Clients.Open“选择不同的(a.Client)作为客户端”_
&“来自Master_Projections a”_
&“其中客户端不在(”_
&“选择不同的客户端ID”_
&“来自客户(翻译);”_
,conn.RBRS_conn,adOpenKeyset,adlock悲观
MEExcluded_Clients.Open“选择*来自已排除的客户端”_
,conn.RBRS_conn,adOpenKeyset,adlock悲观
端接头
//将新记录添加到客户端
私有子cmdAddNew_Click()
如果“未确认”,则
添加记录
如果结束
端接头
私有函数AddRecord()
使用mClient\u翻译
.AddNew
.Fields(“ClientID”)=Me.lst未确认
.Fields(“clientabr”)=Me.txtTmpShort
.Fields(“ClientName”)=Me.txtTmpLong
.更新
以
更新记录
端函数
私有函数UpdateRecords()
Me.LST未确认的重新查询
端函数
//加载事件(施工后)
专用子表单_加载()
Set lstunfirmond.Recordset=mUnmatched\u Clients//将记录集链接到列表框中
Set Me.Recordset=mClient\u
端接头
//破坏方法
专用子表单_Close()
设置连接=无
设置异常=无
Set lstunfirmond.Recordset=Nothing
设置我。记录集=无
Set mUnmatched\u Clients=Nothing
Set meexcluded_Clients=Nothing
设置mClient\u Translations=Nothing
端接头

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

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


Mohgeroth,我觉得你的问题有点混乱,不太清楚。我“认为”您要问的是,如何在不使用数据绑定的情况下使用Access连续表单?这就是你要问的吗?看看你能不能把你的问题改成一句话。也许会改变你的头衔。赛斯