如何构造一个 SQL VBA 块,这样我就可以执行多个 SQL 语句,而不必为每个单独的 SQL 语句打开数据库?
例如,我尝试了以下两个代码块,但得到一个错误,指出 FROM 子句有问题。
Dim dbs As Database
Set dbs = OpenDatabase("path\database.mdb")
dbs.Execute " INSERT INTO table1 (col1,col2,col3) " _
& "SELECT F1,F2,Format$(Now(),'Short Date') " _
& "FROM table2" _
& "DROP table2;"
dbs.Close
和
Dim dbs As Database
Set dbs = OpenDatabase("path\database.mdb")
dbs.Execute " INSERT INTO table1 (col1,col2,col3) " _
& "SELECT F1,F2,Format$(Now(),'Short Date') " _
& "FROM table2 " _
& "GO " _
& "DROP TABLE table2
dbs.Close