How can I execute a query to return records in an ms-access database using VBA code?
-
yes it will return paths to pictures stored locally in db and id of eachOghenero E.– Oghenero E.2010-12-31 03:46:33 +00:00Commented Dec 31, 2010 at 3:46
-
Where do you want them returned and how?David-W-Fenton– David-W-Fenton2011-06-12 21:22:00 +00:00Commented Jun 12, 2011 at 21:22
Add a comment
|
2 Answers
Take a look at this tutorial for how to use SQL inside VBA:
http://www.ehow.com/how_7148832_access-vba-query-results.html
For a query that won't return results, use (reference here):
DoCmd.RunSQL
For one that will, use (reference here):
Dim dBase As Database
dBase.OpenRecordset
4 Comments
Oghenero E.
@Remou please more info on DoCmd.RunQuery, i don't want to use SQL, I have the Query already done in ms-access
Fionnuala
oops Openquery : msdn.microsoft.com/en-us/library/bb238028(v=office.12).aspx . With Open query you will get warning messages, but they can be turned off and on again if they become a problem.
Oghenero E.
@Remou thanks, i have a table in ms-access that contains paths to pictures locally and want to print that, pls help me chek this link stackoverflow.com/questions/4567204/…
David-W-Fenton
It's simply never a good idea to turn off SetWarnings. For one, you will then not know if something went wrong. That is, DoCmd.SetWarnings False doesn't just turn off the confirmation prompt, but also turns off the reporting of any errors. And in the case of DoCmd.RunSQL, you can't know that your entire update succeeded, because the SQL will be executed and as many UPDATEs/INSERTs as possible completed. I do not know if DoCmd.OpenQuery has the same deficiency, but it likely does. For a replacement that implements @Remou's first suggestion, search SO for my SQLRun() function.