Expand|Select|Wrap|Line Numbers
- rst.Save Filename, Format
The Filename Parameter is the full path and filename to the file you wish to use to hold the contents of the Recordset
The Format Parameter can be 1 of 2 intrinsic constants:
- adPersistADTG (default) - Saves the Recordset in the Microsoft proprietary Advanced Data Tablegram format.
- adPersistXML - Saves the Recordset as XML. If you save the Recordset in XML format, you can easily use the saved XML file as a Data Source for another application or control that understands XML. XML is an emerging Internet Standard for transferring data.
Enough on the Overview - 2 well commented Sub-Routine Procedures will demonstrate how to Save (Persist) a Recordset to a file on disk, and then retrieve it, make a change, and save it back to disk:
Expand|Select|Wrap|Line Numbers
- Public Sub SaveRecordset()
- Dim rst As ADODB.Recordset
- Dim strFile As String
- Set rst = New ADODB.Recordset
- 'Open the recordset from the database
- rst.Open "tblCustomers", CurrentProject.Connection, _
- adOpenStatic, adLockOptimistic
- 'Construct a file name to use (ADTG or XML)
- strFile = CurrentProject.Path & "\Customers.adtg" 'OR
- 'strFile = CurrentProject.Path & "\Customers.xml"
- 'Destroy any existing file. Necessary because the Save Method
- will fail if the specified file already exists.
- On Error Resume Next
- Kill strFile
- Err.Clear
- 'Now save the recordset to disk (ADTG Format)
- rst.Save strFile, adPersistADTG
- 'Close the recordset in memory
- rst.Close
- End Sub
Expand|Select|Wrap|Line Numbers
- Public Sub RetrieveRecordset()
- Dim rst As ADODB.Recordset
- Dim strFile As String
- Set rst = New ADODB.Recordset
- 'Construct a file name to use
- strFile = CurrentProject.Path & "\Customers.adtg" 'OR
- 'strFile = CurrentProject.Path & "\Customers.xml"
- 'Make sure the file exists
- If Len(Dir(strFile)) > 0 Then
- 'Open the recordset from the file
- rst.Open strFile, , adOpenStatic, adLockOptimistic
- 'Reconnect the recordset to the database
- rst.ActiveConnection = CurrentProject.Connection
- 'Make a change and save it
- rst.Fields("ContactTitle") = "Sales Rep"
- rst.Update
- End If
- rst.Close
- Set rst = Nothing
- End Sub