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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening a query thru code

Status
Not open for further replies.

oaquao

Programmer
May 16, 2001
12
US
I have a sub where I'am trying to open up an existing qry
and this error is generated:
Run time error 3265

Item cannot be found in the collection corresponding to the requested name or ordinal

The spelling of the qry is correct.



Dim cmdCurr As New ADODB.Command
Dim catGetParamQry As New ADOX.Catalog

catGetParamQry.ActiveConnection = CurrentProject.Connection
Set cmdCurr = _
catGetParamQry.Procedures("qryActiveEmp").Command
 
Do you get an error if you use Docmd.Openquery "qryActiveEmp" instead ?
 
I do not get an error using DoCmd, but this is a parameterized qry and I was going to pass in a parameter.
As a test I created a similar scenario in a different db and the same error is generated.
 
Try looking in the views collection for the query.

Dim cg As New ADOX.Catalog
Set cg.ActiveConnection = CurrentProject.Connection

Dim v As View
Dim vn As View
For Each v In cg.Views
Debug.Print "views = "; v.Name
If v.Name = "qryActiveEmp" Then
Set vn = v
End If
Next
 
I was experimenting with explicitly using the item property and the index and that worked.
catGetParamQry.Procedures.Item(0).Command

Then I replaced it with the original code
catGetParamQry.Procedures("qryActiveEmp").Command
and now it works fine.

Any idea on why that ocurred? Perhaps reinstall Access

Looking in the views collection also worked.

Thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top