sql in vb

Massoud

Registered User.
Local time
Today, 13:15
Joined
Jul 11, 2002
Messages
37
Hi.
I want to run a sql command in my vb code using:
docmd.runsql "sql command string"
Is there any way to put the result in recordset variable as we do with tables:

dim docs as recordset
set docs= currentdb.openrecordset(tablename)....

Thanks again.
 
Code:
dim strSql as string
dim rstDocs as recordset

'---- set the sql statement and open the recordset 
'----   (instead of dbengine(0)(0) put currentdb)
strsql="Select * from tblDocs"
set rstDocs = dbengine(0)(0).openrecordset(strsql)

'---- do processing

'---- close recordset
rstdocs.close

'---- clear up
set rstDocs=nothing

Try that


Vince
 
Massoud said:
Hi.
I want to run a sql command in my vb code using:
docmd.runsql "sql command string"

Is there any reason why you won't just use a stored query definition?

And, if you are trying to do this with a SELECT query then it won't work as the RunSQL methos only works for ACTION queries.
 
Thank you. It works well.
The reason to use this method is that I don't want to make the query list a long one. and this way i can manage to develop the program easier since every thing is in the code and in hand.
 
Thank you for your consideration,Pat.
So we have another question. Suppose we have two forms: form1 & form2.
There is also a query (myquery) to be run and there is a criteria in this query based on a vlaue in form1. can we run the same query with the same criteria based on a value in form2?
 

Users who are viewing this thread

Back
Top Bottom