VBA/Excel/Access/Word/Access/Recordset to File — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 12:46, 26 мая 2010
Reading a Persisted Recordset
Sub ReadPersistedRecordset()
Dim strFileName As String
strFileName = "c:\test.txt"
If Len(Dir(strFileName)) = 0 Then
msgBox "File Not Found"
Exit Sub
End If
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
rst.ActiveConnection = CurrentProject.Connection
rst.CursorType = adOpenStatic
rst.LockType = adLockOptimistic
rst.Open Source:=strFileName, _
Options:=adCmdFile
Do Until rst.EOF
Debug.Print rst("EmployeeID")
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
End Sub
Save Recordset to a file
Sub PersistRecordset()
Dim strFileName As String
strFileName = "c:\test.txt"
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
rst.ActiveConnection = CurrentProject.Connection
rst.CursorType = adOpenStatic
rst.LockType = adLockOptimistic
rst.Open Source:="Select * from Employees ", _
Options:=adCmdText
On Error Resume Next
Kill strFileName
rst.Save strFileName, adPersistADTG
rst.Close
Set rst = Nothing
End Sub