Avatar of Laurence Martin
Laurence Martin
Flag for United Kingdom of Great Britain and Northern Ireland asked on

Defining a Query in code

I am trying to compile my mdb in Access 2010 and this line of code is throwing up an error:

Set db.QueryDefs("qry13bCreditStatus").SQL = stSQL

The error is "Invalid use of property"

Previously in the same procedure:

set db=opendatabase(stdatapath)

If you can see what I'm doing wrong that would be great.
Microsoft Access

Avatar of undefined
Last Comment
Patrick Matthews

8/22/2022 - Mon
Andy Marshall

The Set is causing the problem, I think.  Try something like:

Dim qdf As DAO.QueryDef
Set qdf = CurrentDb.QueryDefs("qry13bCreditStatus")
qdf.SQL = "SELECT Category FROM Categories"
Patrick Matthews

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Andy Marshall

I think my answer would have worked too!!  Oh well.
Patrick Matthews


Yes, it would have.  For the record, I would not object to a split :)

I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck