DoCmd.RunSQL

  • Thread starter Thread starter Guest
  • Start date Start date
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,
 
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 & ";"
 
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.
 
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
 
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
 
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?
 
I love it! Simplicity (well, almost) at its best. There's always something new to learn with Access

thank you!
 
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
 
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. :)
 
Back
Top