Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run time error when checking for a query

Status
Not open for further replies.

achick

Programmer
May 23, 2007
66
US
I am trying to check if a query exists. Here is my code.
I get a runtime error: Object variable or with block variable not set


Private Sub CmdCheck_Click()
Dim db As Database
Dim qry As QueryDef
Dim i As Integer

For Each qry In db.QueryDefs
If qry.Name = "qryTempcat" Then
i = 1
End If
Next qry

End Sub

Thanks
 
Dim qry As QueryDef
Dim i As Integer

For Each qry In currentDb.QueryDefs
 
Since you have db dim'd, try
Code:
Private Sub CmdCheck_Click()
  Dim db As DAO.Database
  Dim qry As DAO.QueryDef
  Dim i As Integer
  Set db = Currentdb
  For Each qry In db.QueryDefs
    If qry.Name = "qryTempcat" Then
      i = 1
    End If
  Next qry
  Set db = Nothing
End Sub
Or just
Code:
   Dim I as Integer
   I=DCount("*","msysObjects","[type]=5 AND [Name] = 'qryTempCat'")

Duane
Hook'D on Access
MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top