Run-time error '2342'

S

Stapes

Hi
I got this error: -

Run-time error '2342':

A RunSQL action requires an argument consisting of an SQL statement.

using DoCmd.RunSQL strSQL, where STRSQL =

SELECT TM_Customers.PK_Comp, TM_Customers.Co,
TM_Customers.FK_SchoolType, TM_Customers.TLK_Cat, TM_CompContact.Cat,
TM_Customers.Country, TM_Customers.Cnty, TM_Customers.Town,
TM_Customers.Pocd FROM TM_Customers INNER JOIN TM_CompContact ON
TM_Customers.PK_Comp = TM_CompContact.FK_CompID WHERE
(((TM_Customers.TLK_Cat)= 'BU') OR ((TM_CompContact.Cat)='BU'));

The SQL works fine in a query.

Any ideas?

Stapes
 
S

Stapes

Hi
I got this error: -

Run-time error '2342':

A RunSQL action requires an argument consisting of an SQL statement.

using DoCmd.RunSQL strSQL, where STRSQL =

SELECT TM_Customers.PK_Comp, TM_Customers.Co,
TM_Customers.FK_SchoolType, TM_Customers.TLK_Cat, TM_CompContact.Cat,
TM_Customers.Country, TM_Customers.Cnty, TM_Customers.Town,
TM_Customers.Pocd FROM TM_Customers INNER JOIN TM_CompContact ON
TM_Customers.PK_Comp = TM_CompContact.FK_CompID WHERE
(((TM_Customers.TLK_Cat)= 'BU') OR ((TM_CompContact.Cat)='BU'));

The SQL works fine in a query.

Any ideas?

Stapes

Hi

I tried removing all the brackets from the query. No improvement.

Stapes
 
D

Douglas J. Steele

You cannot use RunSQL with a Select statement: it only works with Action
queries (SELECT INTO, UPDATE, DELETE)

What exactly are you trying to do?
 
S

Stapes

You cannot use RunSQL with a Select statement: it only works with Action
queries (SELECT INTO, UPDATE, DELETE)

What exactly are you trying to do?

--
Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele
(no e-mails, please!)







- Show quoted text -

Hi

I have 2 types of record - Customer and Contact.
Each has a category field. The Contacts work for the Companies but do
not necessarily have the same Category. i.e. All schools might have
Category TEACH. Teachers in the school might share the same Category.
However, there may be other contacts within the school who are not
Teachers, such as Head of Special Needs, etc.
However, for the purposes of setting up a Mail Merge, we might want to
pull off all the records of a particular Category, whether or not they
are Customer records or Contact records.

My SELECT statement is trying to pull off all Customer records were
either the Customer Category equals the selection, or a contact record
equals the selection.

Quite aside from all that - the query works as a query. Just not in
VBA. Seems like a bug to me.

Stapes
 
D

Douglas J. Steele

It's certainly not a bug. It's by design. Running a Select statement doesn't
really make sense in VBA.

What do you intend to do with the results of running the query? About the
only thing you can do with a Select statement in VBA is to open a recordset
and then loop through that recordset.
 
S

Stapes

Hi

You are dead right. I left out the INTO part of my SQL statement.

Thanks

Stapes
 

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

Similar Threads


Top