A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

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



 
 
Thread Tools Display Modes
  #1  
Old December 23rd, 2009, 04:22 PM posted to microsoft.public.access.queries
Peter
external usenet poster
 
Posts: 1
Default DoCmd.RunSQL HELP!!! I will not work!

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
  #2  
Old December 23rd, 2009, 05:19 PM posted to microsoft.public.access.queries
Gina Whipp
external usenet poster
 
Posts: 3,500
Default DoCmd.RunSQL HELP!!! I will not work!

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

"Peter" wrote in message
...
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



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 08:10 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.