DoCmd.RunSQL

G

Guest

<shaking my head again

can someone tell me why this sql

sqlStatement = "select tblvehicles.vehid from tblvehicles where tblvehiclesvehid = " & Me.txtVehID & ";

DoCmd.RunSQL sqlStatemen

gives me the error: "A RunSQL action requires an argument consisting of an SQL statement."

tia,
 
K

Kevin3NF

sqlStatement = "select tblvehicles.vehid from tblvehicles where tblvehicles
.. vehid = " & Me.txtVehID & ";"

Are you missing a dot in the where clause? remove the spaces dded for
exaggeration


--
Kevin Hill
President
3NF Consulting

www.3nf-inc.com/NewsGroups.htm
www.DallasDBAs.com/forum - new DB forum for Dallas/Ft. Worth area DBAs.

JMorrell said:
<shaking my head again>

can someone tell me why this sql:

sqlStatement = "select tblvehicles.vehid from tblvehicles where
tblvehiclesvehid = " & Me.txtVehID & ";"
 
D

Dirk Goldgar

JMorrell said:
<shaking my head again>

can someone tell me why this sql:

sqlStatement = "select tblvehicles.vehid from tblvehicles where
tblvehiclesvehid = " & Me.txtVehID & ";"

DoCmd.RunSQL sqlStatement

gives me the error: "A RunSQL action requires an argument consisting
of an SQL statement." ?

The message is a bit misleading. What it's trying to tell you is that
the argument must be an *action* query -- that is, an update, delete,
append, or make-table query. A select query can't be executed by
RunSQL.
 
G

Guest

Of course... somehow I knew that. I'm trying to validate a users data entry of a value in another table. Is there a more elegant way of doing this?

again, tia
 
P

Pavel Romashkin

Try

Dim Rst as ADODB.Recordset
Set Rst = New ADODB.Recordset
Rst.Open "your sql here", CurrentProject.Connection
Rst.MoveFirst
IF Rst.EOF then MsgBox "No data matches your criteria"
Rst.Close
Set Rst = Nothing

Pavel
 
T

tina

if the user's data entry has to match a value from another table, is it
feasible in your setup to use a combo box for the data entry? with the
LimitToList property set to Yes, the validation is automatic.

hth


JMorrell said:
Of course... somehow I knew that. I'm trying to validate a users data
entry of a value in another table. Is there a more elegant way of doing
this?
 
G

Guest

I love it! Simplicity (well, almost) at its best. There's always something new to learn with Access

thank you!
 
P

Pavel Romashkin

Yet, people ofted get upset when you try to suggest another solution to
their problem than the one they posted. OP is the exception.
This is why I like ?s like "how can I" rather than "why is my 70 line
SQL isn't working". Chances are, there is a 2-line solution if you knew
the entire original problem.

Pavel
 
T

tina

yes, that happens sometimes. but everyone here posts possible solutions with
good intent, and multiple possible solutions can give the requester a choice
of what is easiest and most understandable *for him/her* - and that varies
depending on the person. multiple solutions posted to a question also offer
all of us a chance to learn from each other - i know i very often learn a
lot from the differing solutions others put forth, whether or not i also
posted one. :)
 

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

Run-time error '2342' 5
Access Form Coding 7
running an SQL query 3
A SQL statement in VBA 7
unvalid sql 2
VBA -- SQL 9
DoCmd.RunSQL HELP!!! I will not work! 1
help on simple SQL VB 1

Top