help on simple SQL VB

G

Guest

Hi, I have a form, user needs to select "Carrier" from a drop down list,
later when they hit a button, an email will be sent to the carrier they
choose with other content in the form. I have a table for carrier contact
information named "carrier", it has an "Email" field for email, and a
"Carrier" field for carrier name. I wrote these codes for the on_click event,
but could not get it to work

Dim RParty As String
Dim StrSQL As String
RParty = Me!Carrier
StrSQL = "SELECT Email " & _
"FROM Carrier " & _
"WHERE Carrier = '" & RParty & "'"
DoCmd.RunSQL StrSQL

I use Msgbox to see the SQL string, and it looks fine, but RunSQL keeps
saying error 2342, A RunSQL action requires an argument consisting of a SQL
statement. I even tried using a real carrier name instead of a variable in
the query, but still get the error message, it really drives me crazy as the
query is so simple. please help.
 
M

Matthias Klaey

Accessvirgin said:
Hi, I have a form, user needs to select "Carrier" from a drop down list,
later when they hit a button, an email will be sent to the carrier they
choose with other content in the form. I have a table for carrier contact
information named "carrier", it has an "Email" field for email, and a
"Carrier" field for carrier name. I wrote these codes for the on_click event,
but could not get it to work

Dim RParty As String
Dim StrSQL As String
RParty = Me!Carrier
StrSQL = "SELECT Email " & _
"FROM Carrier " & _
"WHERE Carrier = '" & RParty & "'"
DoCmd.RunSQL StrSQL

I use Msgbox to see the SQL string, and it looks fine, but RunSQL keeps
saying error 2342, A RunSQL action requires an argument consisting of a SQL
statement. I even tried using a real carrier name instead of a variable in
the query, but still get the error message, it really drives me crazy as the
query is so simple. please help.

You can use DoCmd.RunSQL only for action queries, i.e., INSERT,
UPDATE, DELETE queries or data definition language, but not for a
SELECT query.
How do you want to use this query?

HTH
Matthias Kläy
 

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

Top