aziz rasul
05-16-2002, 01:51 AM
Can anyone tell me why I get error 91 (i.e. Object variable or With block variable not set) for the following code: -
Public Function Method_Three()
On Error GoTo Err_Method_Three
Dim dbs As Database
Dim tdf As TableDef
Dim rst As Recordset
Dim qdfDelete_1 As QueryDef
Dim qdfDelete_2 As QueryDef
Dim strSQL_1 As String, strSQL_2 As String
strSQL_1 = "DELETE [tblTable - Query Collection].* FROM [tblTable - Query Collection];"
strSQL_2 = "Delete [tblTable - Query Collection].[DAO Name] FROM [tblTable - Query Collection] WHERE "
strSQL_2 = strSQL_2 & "(([tblTable - Query Collection].[DAO Name]) Like ""MSys*""));"
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tblTable - Query Collection", dbOpenDynaset)
Set qdfDelete_1 = dbs.CreateQueryDef("", strSQL_1)
Set qdfDelete_2 = dbs.CreateQueryDef("", strSQL_2)
qdfDelete_1.Execute dbFailOnError
With dbs
For Each tdf In .TableDefs
With rst
.AddNew
![DAO Name] = tdf.Name
.Update
End With
Next tdf
End With
qdfDelete_2.Execute dbFailOnError
MsgBox "DAO Collection Updated."
Exit_Method_Three:
Exit Function
Err_Method_Three:
MsgBox Err.Description & "The Error is in Driver Number " & tdf.Name
'Resume Exit_Method_Three
qdfDelete_1.Close
qdfDelete_2.Close
dbs.Close
End Function
The code errors on Set qdfDelete_2
Public Function Method_Three()
On Error GoTo Err_Method_Three
Dim dbs As Database
Dim tdf As TableDef
Dim rst As Recordset
Dim qdfDelete_1 As QueryDef
Dim qdfDelete_2 As QueryDef
Dim strSQL_1 As String, strSQL_2 As String
strSQL_1 = "DELETE [tblTable - Query Collection].* FROM [tblTable - Query Collection];"
strSQL_2 = "Delete [tblTable - Query Collection].[DAO Name] FROM [tblTable - Query Collection] WHERE "
strSQL_2 = strSQL_2 & "(([tblTable - Query Collection].[DAO Name]) Like ""MSys*""));"
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tblTable - Query Collection", dbOpenDynaset)
Set qdfDelete_1 = dbs.CreateQueryDef("", strSQL_1)
Set qdfDelete_2 = dbs.CreateQueryDef("", strSQL_2)
qdfDelete_1.Execute dbFailOnError
With dbs
For Each tdf In .TableDefs
With rst
.AddNew
![DAO Name] = tdf.Name
.Update
End With
Next tdf
End With
qdfDelete_2.Execute dbFailOnError
MsgBox "DAO Collection Updated."
Exit_Method_Three:
Exit Function
Err_Method_Three:
MsgBox Err.Description & "The Error is in Driver Number " & tdf.Name
'Resume Exit_Method_Three
qdfDelete_1.Close
qdfDelete_2.Close
dbs.Close
End Function
The code errors on Set qdfDelete_2