sql in a batch file

R

resueman

-----Original Message-----
is there any way to execute a "batch" of sql statements in an access database?
.

Try this Steve:

1) Create a table SQLBATCH to include a field
SQL_STATEMENT (Memo type to have enough space for your SQL
statements.)
2) Put your sql statements in the table.
3) copy this function to a module in the same database.

Function runSQL()

Dim rst As Recordset

Set rst = CurrentDb.OpenRecordset("select SQL_STATEMENT
from " & _
"SQLBATCH where
SQL_STATEMENT Is Not Null")

'if SQLBATCH is empty
If rst.RecordCount < 0 Then
Exit Function
End If

While Not rst.EOF 'execute all SQL statements

CurrentDb.Execute rst(0)
rst.MoveNext
Wend

rst.Close

End Function

3) execute runSQL()

NOTE: your sql statements have to be valid of course. I
also assumed that
you have quite a few sql statements.
 

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