编辑经过更多研究后,我发现我不能将连续表单与未绑定表单一起使用,因为它一次只能引用一条记录。鉴于我已经改变了我的问题......
我有一个示例表单,它可以提取数据以作为中介输入到表格中。
最初表单是未绑定的,我打开到两个主要记录集的连接。我将列表框的记录集设置为其中之一,将表单记录集设置为另一个。
问题是我无法添加记录或更新现有记录。尝试键入字段几乎没有任何作用,就好像该字段被锁定(事实并非如此)。记录集的设置是 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