Following the answer to this question, I execute different queries stored in a .txt file using the following code:
Dim vSql As Variant
Dim vSqls As Variant
Dim strSql As String
Dim intF As Integer
intF = FreeFile()
Open "MyFile.txt" For Input As #intF
strSql = Input(LOF(intF), #intF)
Close intF
vSql = Split(strSql, ";")
On Error Resume Next
For Each vSqls In vSql
DoCmd.RunSQL vSqls
Next
The queries are separated by ;
, and each query is preceded by a comment line, starting with '
and ending with ;
(so that it gets split by vSql = Split(strSql, ";")
).
The resulting vSql
variant is composed of valid SQL statements, interspersed with comment lines starting with '
. The current code works, but I would like to remove the On Error Resume Next
so that a faulty SQL statement returns an error instead of being ignored.
How can I remove the rows starting with '
in the variant before executing the For Each
loop? Or is there another way to accomplish my goal? The comment character can be changed if necessary.