abenitez77
IS-IT--Management
I have this code that loops thru the querydef's and deletes the passthru queries, but it always leaves out a few. When I tried to trap an error, it does not give me the error description. It also does not finishing looping thru all the querydefs. Why does it not catch all of them?
Function ClearPassThruQueries()
'On Error Resume Next
On Error GoTo ClearODBC_Err
Dim daoDB As DAO.Database
Dim daoQDF As DAO.QueryDef
Set daoDB = CurrentDb()
cnt = daoDB.QueryDefs.Count
For Each daoQDF In daoDB.QueryDefs
'daoQDF.Type = 0 Are Local queries, 112 Are Passthru queries
If daoQDF.Name = "ToolSettings" Or daoQDF.Name = "DataList" Or daoQDF.Name = "Projects" Or daoQDF.Type = 0 Then
'Don't Delete these connections/queries.
Else
'Name matched the naming spec, so zap it!
daoDB.QueryDefs.Delete (daoQDF.Name)
'Refresh the list of remaining QueryDef objects
daoDB.QueryDefs.Refresh
End If
Next
ClearODBC_Err:
ClearPassThruQueries = False
MsgBox "ClearODBC encountered an unexpected error: " & Err.Description
End Function
Function ClearPassThruQueries()
'On Error Resume Next
On Error GoTo ClearODBC_Err
Dim daoDB As DAO.Database
Dim daoQDF As DAO.QueryDef
Set daoDB = CurrentDb()
cnt = daoDB.QueryDefs.Count
For Each daoQDF In daoDB.QueryDefs
'daoQDF.Type = 0 Are Local queries, 112 Are Passthru queries
If daoQDF.Name = "ToolSettings" Or daoQDF.Name = "DataList" Or daoQDF.Name = "Projects" Or daoQDF.Type = 0 Then
'Don't Delete these connections/queries.
Else
'Name matched the naming spec, so zap it!
daoDB.QueryDefs.Delete (daoQDF.Name)
'Refresh the list of remaining QueryDef objects
daoDB.QueryDefs.Refresh
End If
Next
ClearODBC_Err:
ClearPassThruQueries = False
MsgBox "ClearODBC encountered an unexpected error: " & Err.Description
End Function