Reputation: 3
I'm looking for a way to create an in-memory datasheet form. And I like the idea of using a disconnected ADODB Recordset. And at first glance it works. But after refreshing the form (F5 key or Refresh All button), the form loses the recordset, and reassigning it causes MS ACCESS to crash. If, instead of reassigning the recordset, you close and reopen the form, the crash does not occur. But this option is not suitable for me, because I plan to use in-memory datasheet in the subform, and in this case I will have to close and reopen the parent form, which is unacceptable. How to solve the problem? This is my Form's code:
Option Compare Database
Dim myRecSet As ADODB.Recordset
Private Sub Form_Open(Cancel As Integer)
Init
End Sub
Private Sub Form_Current()
If Me.Recordset Is Nothing Then Init ' << Causes MS Access crash after F5 key press
End Sub
Private Sub Init()
Set myRecSet = New ADODB.Recordset
With myRecSet
.Fields.Append "ID", adInteger, , adFldKeyColumn
.Fields.Append "someText", adVarChar, 20, adFldMayBeNull
.CursorType = adOpenKeyset
.CursorLocation = adUseClient
.LockType = adLockPessimistic
.Open
End With
myRecSet.AddNew
myRecSet.Fields(1) = "First text"
myRecSet.Update
myRecSet.AddNew
myRecSet.Fields(1) = "Second text"
myRecSet.Update
Set Me.Recordset = myRecSet
End Sub
I've tried different versions of the Microsoft ActiveX Data Objects Library reference, but it didn't help.
Upvotes: 0
Views: 30