G
Guest
Hey all
Posted this last week but I don't think I did it very well. I've created an Access database that allows you to link to an external source (such as an Excel worksheet or another Access database) and perform search-and-replace functions to another linked source (Excel, Access, etc.). This has a myriad of uses and is actually quite useful (mostly because of the elimination of human error). But the actual processing of the updates seems to take forever. Here is the code in question (and the definition of a UDT). Is there some reason that this sub could take so long to run? (For instance, I had 73 records to update, and I started it before I began typing this post, and it's still not done yet.
Here is the code - watch for line wrap
Access 2000, Windows 200
THE FOLLOWING IS CONATINED IN A CODE MODUL
' Describes one field in a tabl
Public Type OneFiel
FName As Strin
DataType As Lon
End Typ
' Describes all the info needed about the update of one tabl
Public Type OneJo
' This is the info about the source of the updated dat
SourceTable As Strin
SourceCol As OneFiel
SLinkCol As OneFiel
' This is the table that is going to receive the updated dat
UpdateTable As Strin
UpdateCol As OneFiel
ULinkCol As OneFiel
End Typ
Public objJobs() As OneJo
THIS IS THE SLOW SU
Private Sub snr(
Dim J As Integer, intRowCount As Integer, i As Intege
Dim strSQL As String, strReplace As String, strWhere As String, strCap As String, strPer As Strin
Dim objConn As ADODB.Connectio
Dim objRS As ADODB.Recordse
Dim strR
' **********************************************************************************
' This sub loops through all the items in the objJobs array, and performs each updat
' described
' **********************************************************************************
For J = 0 To UBound(objJobs
lblStatus.Caption = "Processing (Job " & CStr(J + 1) & " of " & CStr(UBound(objJobs) + 1) & ")
strCap = lblStatus.Captio
Me.Repain
With objJobs(J
' Establish a connection to the current databas
Set objConn = CurrentProject.Connectio
strSQL = "SELECT [" & .SLinkCol.FName & "],[" & .SourceCol.FName & "] FROM [" & .SourceTable & "]
Set objRS = objConn.Execute(strSQL
strRS = objRS.GetRow
objRS.Clos
objConn.Clos
intRowCount = UBound(strRS, 2
For i = 0 To intRowCoun
lblStatus.Caption = strCap & vbCrLf & "Record " & CStr(i + 1) & " of " & CStr(intRowCount + 1
Me.Repain
If Not IsNull(strRS(0, i)) The
strWhere = strRS(0, i
Els
strWhere = "<NULL>
End I
' Check the data types of the various column
Select Case .ULinkCol.DataTyp
Case 0, 130, 200, 201, 202, 203 ' STRING value
strWhere = "'" & strWhere & "'
Case 7, 133, 134, 135 ' DAT
strWhere = "#" & strWhere & "#
Case Els
strWhere = strWher
End Selec
strWhere = "[" & .ULinkCol.FName & "]=" & strWher
If Not IsNull(strRS(1, i)) The
strReplace = strRS(1, i
Els
strReplace = "''
End I
Select Case .UpdateCol.DataTyp
Case 0, 130, 200, 201, 202, 203 ' STRING value
strReplace = "'" & strReplace & "'"
Case 7, 133, 134, 135 ' DATE
strReplace = "#" & strReplace & "#"
Case Else
strReplace = Val(strReplace)
End Select
strSQL = "UPDATE [" & .UpdateTable & "] SET [" & .UpdateCol.FName & "]=" & strReplace & " WHERE " & strWhere
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
Next
End With
Next
Set objRS = Nothing
Set objConn = Nothing
End Sub
Posted this last week but I don't think I did it very well. I've created an Access database that allows you to link to an external source (such as an Excel worksheet or another Access database) and perform search-and-replace functions to another linked source (Excel, Access, etc.). This has a myriad of uses and is actually quite useful (mostly because of the elimination of human error). But the actual processing of the updates seems to take forever. Here is the code in question (and the definition of a UDT). Is there some reason that this sub could take so long to run? (For instance, I had 73 records to update, and I started it before I began typing this post, and it's still not done yet.
Here is the code - watch for line wrap
Access 2000, Windows 200
THE FOLLOWING IS CONATINED IN A CODE MODUL
' Describes one field in a tabl
Public Type OneFiel
FName As Strin
DataType As Lon
End Typ
' Describes all the info needed about the update of one tabl
Public Type OneJo
' This is the info about the source of the updated dat
SourceTable As Strin
SourceCol As OneFiel
SLinkCol As OneFiel
' This is the table that is going to receive the updated dat
UpdateTable As Strin
UpdateCol As OneFiel
ULinkCol As OneFiel
End Typ
Public objJobs() As OneJo
THIS IS THE SLOW SU
Private Sub snr(
Dim J As Integer, intRowCount As Integer, i As Intege
Dim strSQL As String, strReplace As String, strWhere As String, strCap As String, strPer As Strin
Dim objConn As ADODB.Connectio
Dim objRS As ADODB.Recordse
Dim strR
' **********************************************************************************
' This sub loops through all the items in the objJobs array, and performs each updat
' described
' **********************************************************************************
For J = 0 To UBound(objJobs
lblStatus.Caption = "Processing (Job " & CStr(J + 1) & " of " & CStr(UBound(objJobs) + 1) & ")
strCap = lblStatus.Captio
Me.Repain
With objJobs(J
' Establish a connection to the current databas
Set objConn = CurrentProject.Connectio
strSQL = "SELECT [" & .SLinkCol.FName & "],[" & .SourceCol.FName & "] FROM [" & .SourceTable & "]
Set objRS = objConn.Execute(strSQL
strRS = objRS.GetRow
objRS.Clos
objConn.Clos
intRowCount = UBound(strRS, 2
For i = 0 To intRowCoun
lblStatus.Caption = strCap & vbCrLf & "Record " & CStr(i + 1) & " of " & CStr(intRowCount + 1
Me.Repain
If Not IsNull(strRS(0, i)) The
strWhere = strRS(0, i
Els
strWhere = "<NULL>
End I
' Check the data types of the various column
Select Case .ULinkCol.DataTyp
Case 0, 130, 200, 201, 202, 203 ' STRING value
strWhere = "'" & strWhere & "'
Case 7, 133, 134, 135 ' DAT
strWhere = "#" & strWhere & "#
Case Els
strWhere = strWher
End Selec
strWhere = "[" & .ULinkCol.FName & "]=" & strWher
If Not IsNull(strRS(1, i)) The
strReplace = strRS(1, i
Els
strReplace = "''
End I
Select Case .UpdateCol.DataTyp
Case 0, 130, 200, 201, 202, 203 ' STRING value
strReplace = "'" & strReplace & "'"
Case 7, 133, 134, 135 ' DATE
strReplace = "#" & strReplace & "#"
Case Else
strReplace = Val(strReplace)
End Select
strSQL = "UPDATE [" & .UpdateTable & "] SET [" & .UpdateCol.FName & "]=" & strReplace & " WHERE " & strWhere
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
Next
End With
Next
Set objRS = Nothing
Set objConn = Nothing
End Sub