Can I make a delete query directly in vba

  • Thread starter Thread starter Hellen
  • Start date Start date
H

Hellen

Hello,

can I create a delete query directly in vba without
creating a query ?
Example: DELETE Planning.planningID, Planning.ID_PL
FROM Planning
WHERE Planning.planningID =1;

If not: How can I use vba variables in queries. The "1" in
my example should be a variable of vba

Thanks for your help
 
Hellen,

vID = 1
strSQL = "DELETE Planning.planningID, Planning.ID_PL"
strSQL = strSQL & " FROM Planning"
strSQL = strSQL & " WHERE Planning.planningID = " & vID
CurrentDb.Execute strSQL, dbFailOnError

HTH,
Nikos
 
DELETE SQL normally goes with * in JET SQL rather than Field names?

--
HTH
Van T. Dinh
MVP (Access)
 
Okay thanks,

and if it is not a delete query. A normal Select query how
can I this make in vba ? Because I try this, but with
execute access said that he cannot accept a select
query ???
 
Hellen,

CurrentDb.Execute (as well as DoCmd.RunSQL) will only execute action
queries (DELETE, APPEND, UPDATE, MAKE TABLE). You can't use it for
SELECT queries, but there is probably some other way. What are you
trying to achieve?

Nikos
 
I want to do a query and then I would like to put a field,
because there is only 1 record put into a variable!
Thx
 
Hellen,

Can you explain?
What do you need the query for?
Put a field? Where?
One record into a variable? What variable?
Sorry, I can't make any sense out of this.

Nikos
 
Check Access VB Help on the DLookUp() function.

Alternatively, you can create a Recordset based on the Query and retrieve
the value through the Recordset. However, this requires a bit more code so
DLookUp() will be easier for you.
 
Back
Top