Setting SQL for queries using Visual Basic

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all

Can anyone tell me how to use Visual Basic to set the SQL for an existing
query?

If I use:

[QueryDefs]![Name Of Query].SQL = Blahblahblah

It doesn’t work, I assume because the query is not open at the time, and
presumably therefore not in the QueryDefs collection.

Surely I don’t need to open the query up, presenting the user with a set of
results, before I can modify its SQL?

Thanks in advance

David Cleave
 
Try ...

CurrentDb.QueryDefs ... etc.

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 
Depends on if you are using DAO or ADO etc.

Your syntax suggests DAO:

Dim QD as QueryDef
Set QD = MyDB.QueryDefs("MyQuery")
QD.SQL = "blahhhhh"

. .. . . . . .

this will not present the user with the query output
 
Back
Top