VBA and SQL

Spiet

New member
Local time
Today, 20:31
Joined
Apr 2, 2004
Messages
5
What is wrong with this??
strMysql = "Select contactpersoon.email FROM contactpersoon"
DoCmd.RunSQL strMysql

It says that the string isn't a sql statement!

Please help me out! Thanks
 
RunSQL can only be used for Action queries or for Define queries.
Save your query and use the OpenQuery method.

RV
 
Hi

It looks to me like you just need to declare strMysql, ie:

Dim strMysql as String

Then the code should work

Hope this helps
 
Robert_Mc said:
It looks to me like you just need to declare strMysql, ie:

Dim strMysql as String

Then the code should work

RV, has already explained why it won't work. You can't RUN a SELECT Query. You can only run an ACTION query: Append, Delete, Insert, Update, Make Table, etc.

Writing that sort of SQL as a string is a resource eater and will necessitate regular compacts of the database instead of just saving the query as a defined QueryDef.
 

Users who are viewing this thread

Back
Top Bottom