Milhouse4118
New member
- Local time
- Today, 12:57
- Joined
- Aug 2, 2024
- Messages
- 10
I'm looking for the fastest way to update a table boolean field in an access table by way of VBA.  A snipet of my code is below
	
	
	
		
The above code "worked", but the table tblClips has more than 40,000 records. The dictionary "DictClipsDB" could have as many as 40,000 keys. The code executes VERY slowly and I strongly suspect that it is due to the thousands of executions of the SQL statement. Is there a better way to attempt this table update?
I then tried to modify the code as shown below:
	
	
	
		
I attempted to execute the above code and my pc simply locked up. I allowed it to run for more than hour and decided that I may have mis-coded something or it wasn't much of an improvement.
I finally decided to try to get expert advice and I registered on this forum.
I am not at all committed to running a SQL statement or structuring it as I show above. This is just some of my very inexperienced approach came up with. Please guide me to a more efficient way to set a boolean field based on a value in a dictionary object. The dictionary object will have a key value that is identical to the fldLocation value of the record....
Thanks for your help.
- Milhouse4118
 
		Code:
	
	
	For Each vFile In dictClipsDB.Keys
    If Not dictFilesFound.Exists(vFile) Then
        strSql = "UPDATE tblClips SET blnAlive = FALSE WHERE fldLocation = " & cstQuote & vFile & cstQuote
        dictClipsDead(vFile) = "DELETE READY" 'Dir(vFile) ' this should should be eliminated
        DoCmd.SetWarnings False
        DoCmd.RunSQL strSql
        DoCmd.SetWarnings True
    End If
Next vFileThe above code "worked", but the table tblClips has more than 40,000 records. The dictionary "DictClipsDB" could have as many as 40,000 keys. The code executes VERY slowly and I strongly suspect that it is due to the thousands of executions of the SQL statement. Is there a better way to attempt this table update?
I then tried to modify the code as shown below:
		Code:
	
	
	For Each vFile In dictClipsDB.Keys
    If Not dictFilesFound.Exists(vFile) Then
       
        'Writing code to write a REALLY long SQL statement that will update the table for all Non-Found Files.
        x = x + 1
        'FIrst pass build the necessary SQL statement
        If x = 1 Then
            'strSql = "UPDATE [tblClips] SET [blnAlive] = FALSE WHERE fldLocation = " & cstQuote & vFile & cstQuote
            strSql = cstQuote & vFile & cstQuote
        Else
        'Continue adding the missing files to the strSQL Statement
            'strSql = strSql & " OR fldLocation = " & cstQuote & vFile & cstQuote
            strSql = strSql & ", " & cstQuote & vFile & cstQuote
        End If
       
 
    End If
Next vFile
If x > 0 Then
    strSql = "UPDATE [tblClips] SET [blnAlive] = FALSE WHERE [fldLocation] IN (" & strSql & ")"
End If
strMsg = MsgBox("The For Loop has identified " & x & " records as dead.  Proceed with execiuting SQL update of records?", vbYesNo, "TESTING")
If strMsg = vbNo Then Exit Sub
'Time to set all not found values in the database to "DEAD"
DoCmd.SetWarnings False
DoCmd.RunSQL strSql
DoCmd.SetWarnings TrueI attempted to execute the above code and my pc simply locked up. I allowed it to run for more than hour and decided that I may have mis-coded something or it wasn't much of an improvement.
I finally decided to try to get expert advice and I registered on this forum.
I am not at all committed to running a SQL statement or structuring it as I show above. This is just some of my very inexperienced approach came up with. Please guide me to a more efficient way to set a boolean field based on a value in a dictionary object. The dictionary object will have a key value that is identical to the fldLocation value of the record....
Thanks for your help.
- Milhouse4118
 
	 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		
 
 
		 
 
		 
 
		