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. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
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
|
|||
|
|||
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 | |
|
|