A persistent Recordset is a Recordset (typically a dynamic or disconnected Recordset
as discussed in the previous two sections) whose information you save between sessions of your
application into a local "holding file."
To implement a persistent Recordset, you call a Recordset object's Save method
to save it to a file. When you want the saved data back, you call a Recordset object's
Open method with an argument that indicates the name of the file where you previously saved
Recordset data.
You need to take the following steps in your code to implement a persistent
Recordset object:
-
Make sure you have an open Recordset object with which to work.
-
Call the Recordset object's Save method with two arguments:
• The first argument represents the name of the file where you will save the
Recordset object's data.
• The second argument represents the data format that you will use to save data
to the file. As of this writing, there's only one possible value for this argument,
adPersistADTG.
-
When you want to retrieve previously saved information from a file into a Recordset,
call the Recordset's Open method, passing to the Open method as its first
and only argument the name of the file where you previously saved the Recordset information.
Listing 8.15 gives an example of code that implements a persistent disconnected
Recordset.
LISTING 8.15
CODE THAT IMPLEMENTS A PERSISTENT RECORDSET
'Assumes that rs has been
'previously declared and initialized
Private Sub cmdSaveDisconn_Click()
If Dir$("C:\trash\mydata.dat") <> "" Then
Kill "C:\trash\mydata.dat"
End If
rs.Save "C:\Trash\MyData.dat", adPersistADTG
End Sub
Private Sub cmdRetrieveDisconn_Click()
Set rs = Nothing
Set rs = New ADODB.Recordset
rs.Open "C:\Trash\MyData.dat"
End Sub