DoCmd.RunSQL HELP!!! I will not work!

P

Peter

Hi all, I'm quite new to Access VBA (normally only work in Excel VBA).

I was hoping the below code would return a SELECT query...

Could anyone tell me why this code always returns with Run-time error
'2342' A RunSQL action requires an arguement consisting of an SQL
statement.?

And if you could tell me the solution that would be great!


Sub VBA_control_SQL_the_adventure_begins()

Dim table_name As String
Dim SQL As String

SQL = "SELECT tblstaff.[Firstname], tblstaff.Lastname " & _
"FROM tblstaff;"
DoCmd.RunSQL SQL

End Sub


Thanks for your help,

Peter
 
G

Gina Whipp

Peter,

RunSQL requires an *action* query, such as... Append and/or Update. Yours
is a Select query... you need to use something like:

Set rs = CurrentDb.OpenRecordset(SQL)

OR

Dim MyRecordSource As String

MyRecordSource = ""SELECT tblstaff.[Firstname], tblstaff.Lastname FROM
tblstaff"

OR

MyRecordSource = SQL

If you tell us what you are trying to do... filter a combo box, fill a form,
use as a RecrodSource we can give you better assistance.

--
Gina Whipp

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top