Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / General 2 / April 2007

Tip: Looking for answers? Try searching our database.

QueryDefs("name") always returning first QueryDef in collection

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tommy  Hayes - 30 Apr 2007 16:03 GMT
Hello all,

I have the following code snippet in my Access app:

Dim dbQueryDef As QueryDef
Set dbQueryDef = CurrentDb.QueryDefs("QUERY_NAME") ' (1)
Set dbQueryDef = CurrentDb.QueryDefs(26) ' (2)

Line (1) does not do as I expect it - it always returns the first
QueryDef in the QueryDefs collection (seen by examining the QueryDefs
object at debug time).

However if I pass the ordinal of the correct QueryDef as in line (2)
above then it works fine.

Anyone know what is going on? Is the string in (1) above being
converted into 1 before being passed to the Item(Item) method of the
collections? I'm a VBA newbie so please excuse the innocence of this
question.

Thanks,
Tommy.

PS: It's an Access 2000 file being run from within Access 2003 if
that's a factor. I need to keep it in 2000 format for the client.
Rick Brandt - 30 Apr 2007 16:09 GMT
Tommy Hayes wrote:
> Hello all,
>
[quoted text clipped - 15 lines]
> collections? I'm a VBA newbie so please excuse the innocence of this
> question.

I use that first syntax all the time and have never had any problems.
You're quite sure you are spelling the query name correctly right?

Signature

Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt   at   Hunter   dot   com

Tommy  Hayes - 30 Apr 2007 16:19 GMT
> You're quite sure you are spelling the query name correctly right?

Yeah I've checked and re-checked. Weirder thing again is the
application runs fine on one computer but not on another, with both
computers having the exact same version of MS Access on them.

I'm currently re-installing Access on the offending computer in case
something was corrupted on that side.

Thanks,
Tommy.
Aaron Kempf - 30 Apr 2007 20:45 GMT
and both databases are MDB?

you might have stumbled into someone SMART enough to use ADP and ADP doesn't
need that syntax

in ADP we use TSQL to edit stored procedures

> > You're quite sure you are spelling the query name correctly right?
>
[quoted text clipped - 7 lines]
> Thanks,
> Tommy.
Aaron Kempf - 30 Apr 2007 20:44 GMT
this type of code isn't necessary any longer

ALTER PROCEDURE SPHAPPY
AS
SELECT *
FROM SYSOBJECTS

move on kids

> Hello all,
>
[quoted text clipped - 21 lines]
> PS: It's an Access 2000 file being run from within Access 2003 if
> that's a factor. I need to keep it in 2000 format for the client.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.