sarah_m3
September 26th, 2001, 08:51 AM
Hi
I have a .sql file which I need to execute by calling it through my VB code. How is this done? Please help
Sarah
baronq
September 26th, 2001, 09:08 AM
Hi,
First make sure you have a DAO-reference in your references, so VB knows what a database is. Import the sql-code into a string in your program and then execute it like this:
dim datDb as Database
dim rsResult as Recordset
set datdb = YourDatabase
set rsresult = datdb.openrecordset(yourstring, dbopendynaset)
do while not rsresult.eof
print rsresult.fields(0) 'show first tupel
rsresult.movenext
loop
rsresult.close
datdb.close
set rsresult=nothing
set datdb = nothing
This only works with select-statements, if you have other statements, like insert or delete, you've gotta use Querydef:
dim datDb as Database
dim qdfQuery as Querydef
set datdb = YourDatabase
set qdfQuery=datDB.createquerydef(Name, Yourquery)
qdfquery.execute
datdb.querydefs.delete qdfquery.name
set qdfquery=nothing
datdb.close
set datdb=nothing
Hope to have been of help,
BaronQ
Sam_Cheung
October 12th, 2001, 11:35 AM
I used to use open file to read the contents into a variable, then use SQLExec to execute it. I hope it is helpfule.
Sam