Can I make a delete query directly in vba

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
 
N

Nikos Yannacopoulos

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
 
V

Van T. Dinh

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

--
HTH
Van T. Dinh
MVP (Access)
 
H

Hellen

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 ???
 
N

Nikos Yannacopoulos

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
 
E

Ellen

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
 
N

Nikos Yannacopoulos

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
 
V

Van T. Dinh

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.
 

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