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.
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.
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.
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