isladogs
MVP / VIP
- Local time
- Today, 23:48
- Joined
- Jan 14, 2017
- Messages
- 18,209
Hi
Thought I'd ask a question for a change.
I've been looking at this for a couple of hours and a new set of eyes may help! I expect I'm missing something obvious
I have a large table of about 16000 records which contains details of all database objects including table fields, form row sources, module code etc etc
The table is used in routines to search for objects containing selected text strings and where necessary replace them (similar to VTools deep search)
The table is part of a linked SQL server BE
All works fine with one exception.
The table includes a boolean field 'Exclude' which can be set to true to omit selected objects from the search. After the search, it is reset to false
The field is indexed in the SQL table
Setting the field true for a large number of objects works quickly
However resetting false causes timeouts with anything more than about 200 records. I can't see any reason for this
I have tried increasingly complex code to:
a) turn off timeouts (set to 0)
b) loop through each time a batch of records is updated but it still fails after 2 or 3 loops
The code below is intended to reset all records to false
It includes both a) & b)
BTW: I've tested with a local copy of the table and it works - just as you would expect.
Thought I'd ask a question for a change.
I've been looking at this for a couple of hours and a new set of eyes may help! I expect I'm missing something obvious
I have a large table of about 16000 records which contains details of all database objects including table fields, form row sources, module code etc etc
The table is used in routines to search for objects containing selected text strings and where necessary replace them (similar to VTools deep search)
The table is part of a linked SQL server BE
All works fine with one exception.
The table includes a boolean field 'Exclude' which can be set to true to omit selected objects from the search. After the search, it is reset to false
The field is indexed in the SQL table
Setting the field true for a large number of objects works quickly
However resetting false causes timeouts with anything more than about 200 records. I can't see any reason for this
I have tried increasingly complex code to:
a) turn off timeouts (set to 0)
b) loop through each time a batch of records is updated but it still fails after 2 or 3 loops
The code below is intended to reset all records to false
It includes both a) & b)
Code:
Private Sub cmdClearAll_Click()
On Error GoTo Err_Handler
Me.lblInfo.visible = True
Me.lblInfo.Caption = "Updating list of excluded items . . ."
DoCmd.Hourglass True
DoEvents
UpdateExclude:
N = DCount("*", "tblDatabaseObjects", "Exclude = True")
' Debug.Print N
'update display
Me.LstExclude.Requery
Me.lblExcludeTotal.Caption = "Total objects excluded = " & N
Me.lblExcludedItemsTotal.Caption = Me.lblExcludeTotal.Caption
DoEvents
strSQL = "UPDATE DISTINCTROW tblDatabaseObjects SET tblDatabaseObjects.Exclude = False" & _
" WHERE tblDatabaseObjects.Exclude = True;"
CurrentDb.QueryTimeout = 0 'set to 0 to prevent timeout
DoEvents
CurrentDb.Execute strSQL, dbSeeChanges
DoEvents
CurrentDb.QueryTimeout = 60 'restore default=60s
'clear controls
For I = 1 To 6
Me("txtExclude" & I) = ""
Me("cboExclude" & I) = ""
Me("cmdClear" & I).enabled = False
Next
'clear table tblDatabaseSQLSearchExcludedItems
strSQL = "UPDATE DISTINCTROW tblDatabaseSQLSearchExcludedItems" & _
" SET tblDatabaseSQLSearchExcludedItems.ExcludedItem = ''," & _
" tblDatabaseSQLSearchExcludedItems.ObjectType = '';"
CurrentDb.Execute strSQL, dbSeeChanges
N = DCount("*", "tblDatabaseObjects", "Exclude = True")
'update display
Me.LstExclude.Requery
Me.lblExcludeTotal.Caption = "Total objects excluded = " & N
Me.lblExcludedItemsTotal.Caption = Me.lblExcludeTotal.Caption
If N > 0 Then GoTo UpdateExclude
Me.lblInfo.visible = False
Me.lblInfo.Caption = ""
DoEvents
DoCmd.Hourglass False
'disable current control
Me.cmdExclude.SetFocus
Me.cmdClearAll.enabled = False
Me.cmdUpdateList.enabled = False
Exit_Handler:
Exit Sub
Err_Handler:
'err 3157- ODBC timeout
If Err = 3157 Then GoTo UpdateExclude: 'Resume Next
'create error message & log
strProc = Application.VBE.ActiveCodePane.CodeModule.ProcOfLine(Application.VBE.ActiveCodePane.TopLine, 0)
PopulateErrorLog
Resume Exit_Handler
End Sub
BTW: I've tested with a local copy of the table and it works - just as you would expect.
Last edited: