esteiner
Programmer
- Oct 31, 2003
- 24
I am scrubbing values of a field1 in an Access table and updating the results in the same table.
The routine runs OK but the size of the database goes to 600+ MB. I must run the compact and repair database operation each time I run the routine. The amount of data to process will continue to increase, so I would like to make this routine as efficient as possible.
I assume that this is caused by the many read/write cycles to the hard disk. Is there a way to store a temp table into RAM before writing to disk? Any help/suggestions to make this more efficient would be appreciated. Below is the code that runs the routine:
Private Sub cmdCleanManfPart_Click()
Dim rs As Recordset ' Recordset object
Dim strTableName As String ' Name of table where export records originate
Dim strSQL As String ' SQL String
Dim intRecordNum As Long ' Record Number being dealt with
Dim strOutLine As String
Dim strOneChar As String
Dim strAllowed As String
Dim strNewMPN As String
Dim intCountRecords As Long ' Total number of records to be processed
Dim strMPN As String
Dim strChanged As String
Dim I As Integer
Set db = DBEngine(0)(0)
' Create the table name from where the export records will orginate
strTableName = "CATALOG"
' Get the number of records to be created (rounding up)
intCountRecords = -Int(-DCount("ManfPartNum_NP", strTableName))
strQuote = Chr$(34)
' Characters Allowed in data
strAllowed = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.()#+%,"
' Get recordset
strSQL = "SELECT ManfPartNum_NP, Changed FROM " & strTableName & ""
Set rs = db.OpenRecordset(strSQL)
For intRecordNum = 1 To intCountRecords
If Not (rs.BOF And rs.EOF) Then
strNewMPN = ""
strChanged = "NO"
strMPN = rs!ManfPartNum_NP
'---------------------------------------------------
'- Build an output string containing the valid -
'- characters from the input string -
'---------------------------------------------------
For I = 1 To Len(strMPN)
strOneChar = Mid$(strMPN, I, 1)
If InStr(strAllowed, strOneChar) > 0 Then
strNewMPN = strNewMPN & strOneChar
End If
If InStr(strAllowed, strOneChar) < 1 Then
strChanged = "YES"
End If
Next I
If Len(strNewMPN) > 0 Then
rs.Edit
rs!ManfPartNum_NP = strNewMPN
rs!Changed = strChanged
rs.Update
End If
rs.MoveNext
End If
Next intRecordNum
rs.Close
sExit:
On Error Resume Next
rs.Close
Set rs = Nothing
Set db = Nothing
Reset
Exit Sub
E_Handle:
MsgBox Err.Description, vbOKOnly + vbCritical, "Error: " & Err.Number
Resume sExit
End Sub
Thank you
-Charlie
The routine runs OK but the size of the database goes to 600+ MB. I must run the compact and repair database operation each time I run the routine. The amount of data to process will continue to increase, so I would like to make this routine as efficient as possible.
I assume that this is caused by the many read/write cycles to the hard disk. Is there a way to store a temp table into RAM before writing to disk? Any help/suggestions to make this more efficient would be appreciated. Below is the code that runs the routine:
Private Sub cmdCleanManfPart_Click()
Dim rs As Recordset ' Recordset object
Dim strTableName As String ' Name of table where export records originate
Dim strSQL As String ' SQL String
Dim intRecordNum As Long ' Record Number being dealt with
Dim strOutLine As String
Dim strOneChar As String
Dim strAllowed As String
Dim strNewMPN As String
Dim intCountRecords As Long ' Total number of records to be processed
Dim strMPN As String
Dim strChanged As String
Dim I As Integer
Set db = DBEngine(0)(0)
' Create the table name from where the export records will orginate
strTableName = "CATALOG"
' Get the number of records to be created (rounding up)
intCountRecords = -Int(-DCount("ManfPartNum_NP", strTableName))
strQuote = Chr$(34)
' Characters Allowed in data
strAllowed = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.()#+%,"
' Get recordset
strSQL = "SELECT ManfPartNum_NP, Changed FROM " & strTableName & ""
Set rs = db.OpenRecordset(strSQL)
For intRecordNum = 1 To intCountRecords
If Not (rs.BOF And rs.EOF) Then
strNewMPN = ""
strChanged = "NO"
strMPN = rs!ManfPartNum_NP
'---------------------------------------------------
'- Build an output string containing the valid -
'- characters from the input string -
'---------------------------------------------------
For I = 1 To Len(strMPN)
strOneChar = Mid$(strMPN, I, 1)
If InStr(strAllowed, strOneChar) > 0 Then
strNewMPN = strNewMPN & strOneChar
End If
If InStr(strAllowed, strOneChar) < 1 Then
strChanged = "YES"
End If
Next I
If Len(strNewMPN) > 0 Then
rs.Edit
rs!ManfPartNum_NP = strNewMPN
rs!Changed = strChanged
rs.Update
End If
rs.MoveNext
End If
Next intRecordNum
rs.Close
sExit:
On Error Resume Next
rs.Close
Set rs = Nothing
Set db = Nothing
Reset
Exit Sub
E_Handle:
MsgBox Err.Description, vbOKOnly + vbCritical, "Error: " & Err.Number
Resume sExit
End Sub
Thank you
-Charlie