I am trying to iterate a table with database names in it, open the database, check if a query exists, if it does delete it, then import a query from the database this code is being executed from. I keep getting a compile time error on the line of Set badqueryname = "qry_InformationMailer" and what I am trying to do with that is set the name of the query to delete. This is the error that line throws
object required
Full syntax:
Option Compare Database
Option Base 1
Private Sub fur()
Dim ws As DAO.Workspace
Dim db As DAO.Database
Dim qd As DAO.QueryDef
Dim rstTableName As DAO.Recordset
Dim myArray() As String
Dim intArraySize As Integer
Dim iCounter As Integer
Dim qryLoop As QueryDef
Dim exists As String
Dim dbs As Database
Dim badqueryname As String
'Compile error of object required on below line
Set badqueryname = "qry_InformationMailer"
Set rstTableName = CurrentDb.OpenRecordset("tbl_Data")
If Not rstTableName.EOF Then
rstTableName.MoveFirst
intArraySize = rstTableName.RecordCount
iCounter = 1
ReDim myArray(intArraySize)
Do Until rstTableName.EOF
myArray(iCounter) = rstTableName.Fields("ProgramName")
iCounter = iCounter + 1
rstTableName.MoveNext
Loop
End If
If IsObject(rstTableName) Then Set rstTableName = Nothing
Set qd = CurrentDb.QueryDefs("qry_InformationMailer")
Set ws = DBEngine(0)
For l = LBound(myArray) To UBound(myArray)
Set db = ws.OpenDatabase("C:\" & Trim(myArray(l)) & ".mdb")
For Each qryLoop In CurrentDb.QueryDefs
If qry.LoopName = badqueryname Then
exists = "Yes"
DoCmd.DeleteObject acQuery, badqueryname
Exit For
End If
Next
On Error Resume Next
db.CreateQueryDef qd.Name, qd.SQl
db.Close
Set db = Nothing
Next l
End Sub