Bob Darlington wrote:
Does anyone have a function which can be used to check tables in a db for
corruption?
I want to run such a routine to ensure that backups are not being saved with
corrupt data.
FWIW I use the code below to scan a single table for bad records. It's
set up to send output to a form, but you could easily modify it to
debug.print.
Public Sub FindBadRecord()
On Error GoTo ErrBadRecord
Dim RS As DAO.Recordset
Dim i As Long
Dim j As Long
Dim tmpx As Variant
Dim SQL As String
With Form_frmDebugger.txtDebugWindow
.Text = "Running..." & vbCrLf
SQL = "SELECT * " & _
"FROM [MyTable]" & _
"ORDER BY [MyTable].[RecID];"
Set RS = CurrentDb.OpenRecordset(SQL)
RS.MoveFirst
Do While Not RS.EOF
' Debug.Print "Reading fields at record # " & RS.Fields(0)
j = j + 1
If j Mod 1000 = 0 Then .Value = .Value & "Read " & j & "
records OK."
For i = 0 To RS.Fields.Count - 1
tmpx = RS.Fields(i).Value
Next i
ResumeBadRecord:
RS.MoveNext
DoEvents
Loop
.Text = .Value & "Done" & vbCrLf
Set RS = Nothing
Exit Sub
ErrBadRecord:
.Text = .Value & "*** Error at [RecID] " &
RS.Fields(0).Value & vbCrLf
.Text = .Value & "*** Error details: " & Err & " " & Error &
vbCrLf
.Text = .Value & vbCrLf
Resume ResumeBadRecord
End With
End Sub
--
Smartin