Access: Err 2342 in SQL SELECT Statement in VBA 
Author Message
 Access: Err 2342 in SQL SELECT Statement in VBA

I am creating a new Access 2002 database using VBA to
select and update records.  I have many existing such
databases that are working fine.

Anytime I create a new SELECT statement using VBA & SQL I
get the following error:

Run-time error '2342':
A RunSQL action requires an argument consisting os an SQL
statement.

This ONLY happens on SELECT statements.  The following
code runs:
strSQL = "DELETE tblTable.* FROM tblTable;"
DoCmd.RunSQL (strSQL)

This generates an error:
strSQL = "SELECT tblTable.* FROM tblTable;"
DoCmd.RunSQL (strSQL)

Any help would be appreciated.
Thanks,
Suzanne

.



Tue, 04 Oct 2005 20:11:25 GMT  
 Access: Err 2342 in SQL SELECT Statement in VBA
Try

strSQL = "SELECT * FROM tblTable;"

Quote:

> I am creating a new Access 2002 database using VBA to
> select and update records.  I have many existing such
> databases that are working fine.

> Anytime I create a new SELECT statement using VBA & SQL I
> get the following error:

> Run-time error '2342':
> A RunSQL action requires an argument consisting os an SQL
> statement.

> This ONLY happens on SELECT statements.  The following
> code runs:
> strSQL = "DELETE tblTable.* FROM tblTable;"
> DoCmd.RunSQL (strSQL)

> This generates an error:
> strSQL = "SELECT tblTable.* FROM tblTable;"
> DoCmd.RunSQL (strSQL)

> Any help would be appreciated.
> Thanks,
> Suzanne

> .



Tue, 04 Oct 2005 22:05:58 GMT  
 Access: Err 2342 in SQL SELECT Statement in VBA
Where is the result of the query going to go?

A select query has to have a 'destination'.
This is normally a recordset object.

Dim db as dao.database
Dim rs as dao.recordset
set db = currentdb()
set rs = db.openrecordset(strSQL)
....process the records

rs.close
set rs = Nothing
set db = nothing

If you were hoping to display the results as a datasheet then you need to
use an Access query.(Or use an unbound form fed from the routine described
above.)

Regards

Peter Russell


Quote:

> I am creating a new Access 2002 database using VBA to
> select and update records.  I have many existing such
> databases that are working fine.

> Anytime I create a new SELECT statement using VBA & SQL I
> get the following error:

> Run-time error '2342':
> A RunSQL action requires an argument consisting os an SQL
> statement.

> This ONLY happens on SELECT statements.  The following
> code runs:
> strSQL = "DELETE tblTable.* FROM tblTable;"
> DoCmd.RunSQL (strSQL)

> This generates an error:
> strSQL = "SELECT tblTable.* FROM tblTable;"
> DoCmd.RunSQL (strSQL)

> Any help would be appreciated.
> Thanks,
> Suzanne

> .



Tue, 04 Oct 2005 22:37:00 GMT  
 Access: Err 2342 in SQL SELECT Statement in VBA
I never tried performing a SELECT with the "docmd"
approach.  I always define a recordset object, a database
object, and the use the SELECT sql string.  The syntax
looks something like this,although I can't be sure this
early in the morning:

DB_object.Recorset_Object(SQL_string)

Quote:
>-----Original Message-----
>I am creating a new Access 2002 database using VBA to
>select and update records.  I have many existing such
>databases that are working fine.

>Anytime I create a new SELECT statement using VBA & SQL I
>get the following error:

>Run-time error '2342':
>A RunSQL action requires an argument consisting os an SQL
>statement.

>This ONLY happens on SELECT statements.  The following
>code runs:
>strSQL = "DELETE tblTable.* FROM tblTable;"
>DoCmd.RunSQL (strSQL)

>This generates an error:
>strSQL = "SELECT tblTable.* FROM tblTable;"
>DoCmd.RunSQL (strSQL)

>Any help would be appreciated.
>Thanks,
>Suzanne

>..

>.



Fri, 07 Oct 2005 19:13:55 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Access: Err 2342 in SQL SELECT Statement in VBA

2. SQL to VBA Error 2342

3. error 2342 with docmd.runsql

4. Help! VB and Access SQL select statement

5. SQL/Access error with SELECT statement

6. VBA in Access ... sql statement with querydef

7. Parameters from VB6 to ACCESS VBA SQL-statement

8. SQL query: from SELECT statement to stored procedure with dynamic PL/SQL

9. Err 429 ActiveXCan't Create Object VBA Dynamics SQL Server

10. ADO: VBA function in select statement

11. ADO: VBA function in select statement

12. Counting records returned by SQL Select statement

 

 
Powered by phpBB® Forum Software