Continuous Form,如何通过外部连接添加/更新记录

发布于 2024-09-01 07:39:45 字数 2643 浏览 4 评论 0原文

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

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

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

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

EDIT After some more research I found that I cannot use a continuous form with an unbound form since it can only reference a single record at a time. Given that I've altered my question...

I have a sample form that pulls out data to enter into a table as an intermediary.

Initially the form is unbound and I open connections to two main recordsets. I set the listbox's recordset equal to one of them and the forms recordset equal to the other.

The problem is that I cannot add records or update existing ones. Attempting to key into the fields does nothing almost as if the field was locked (Which it is not). Settings of the recordsets are OpenKeyset and LockPessimistic.

Tables are not linked, they come from an outside access database seperate from this project and must remain that way. I am using an adodb connection to get the data. Could the separation of the data from the project be causing this?

Sample Code from the Form

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

献世佛 2024-09-08 07:39:46

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

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

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

I found that you cannot update/add to a recordset without the connection string containing both a Provider and a Data Provider for microsoft access database files (external). As stated above I was able to pull and display the records but unless manually using ADO Add/Update methods through hardcode, I don't have those capabilities.

This link has the solution for both SQL and JET connections to do this with external database files using these two provider types. The confusing part was adding the password parameters (for a global file password) in the connection string in the connection class I am using.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文