Al ejecutar una consulta SELECT en vBA me daba error.
error 2342 requiere un argumento.. instruccion sql.......
Las consultas SELECT en principio no se pueden ejecutar como una sql con DOCmd.RunSQL
Buscando soluciones encontre esta.
http://access-excel.tips/access-docmd-runsql-error-2342/
The error message “Run-time error ‘2342’: A RunSQL action requires an argument consisting of SQL statement” is very confusing, it fails to point out the error is caused by using non-action query.
Solution of Error 2342 to select query
The below code creates a Query called “tempQry” using CreateQueryDef Method and then open it using DoCmd.OpenQuery Method.
Just in case “tempQry” already exists in database, DoCmd.DeleteObject Method deletes tempQry if it exists.
Public Sub selectSQL()
Dim qdf As QueryDef
Dim strSQL as String
strSQL = "Select * FROM [Schedule_Table] WHERE [Empl ID]='001'" 'Ponemos la sql que queramos
On Error Resume Next
DoCmd.DeleteObject acQuery, "tempQry"
On Error GoTo 0
Set qdf = CurrentDb.CreateQueryDef("tempQry", strSQL)
DoCmd.OpenQuery ("tempQry"), acViewNormal, acReadOnly
End Sub
Y apara llamarla ponemos
selectSQL
No se si ha salido por aqui, pero por si acaso aqui esta....
Saludos