0% found this document useful (0 votes)
15 views

' Do A Periodic Backup of Records: Private Sub Dim As String Dim As Dim As Dim As String

This VBA code periodically backs up customer records from a "Customers" database table to a text file. It opens the recordset, loops through each record, builds a string of field values separated by pipes, writes each record string to the text file, then closes the file and recordset. The process is run on a timer to provide regular automated backups of the customer data.

Uploaded by

Paul
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

' Do A Periodic Backup of Records: Private Sub Dim As String Dim As Dim As Dim As String

This VBA code periodically backs up customer records from a "Customers" database table to a text file. It opens the recordset, loops through each record, builds a string of field values separated by pipes, writes each record string to the text file, then closes the file and recordset. The process is run on a timer to provide regular automated backups of the customer data.

Uploaded by

Paul
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Private Sub Form_Timer()

' do a periodic backup of records


Dim stFile As String
Dim rs As DAO.Recordset2
Dim fld As DAO.Field2
Dim stData As String

' show status


Me.lblWait.Visible = True
DoEvents

' open the file name - latest data always available


stFile = CurrentProject.Path & “\CustomerBackup.txt”
Open stFile For Output As #1

' get the data


Set rs = CurrentDb().OpenRecordset(“Customers”)
While (Not rs.EOF)
' loop through fields and build the data string
For Each fld In rs.Fields
If (Not fld.IsComplex) Then
stData = stData & fld.Value & “|”
End If
Next

' print
Print #1, Left(stData, Len(stData) - 1)
rs.MoveNext
DoEvents
Wend

' cleanup
rs.Close
Set rs = Nothing
Set fld = Nothing

Close #1

' hide status


Me.lblWait.Visible = False
End Sub

You might also like