Access支持CREATE VIEW
當您從ADO/OleDb的執行。這段代碼工作,因爲CurrentProject.Connection
是ADO對象...
Dim strSql As String
strSql = "CREATE VIEW NHTrips AS" & vbCrLf & _
"SELECT TripID, TripName, StartLocation, State, Distance, MaxGrpSize, Type, Season" & vbCrLf & _
"FROM Trip" & vbCrLf & _
"WHERE State = 'NH';"
CurrentProject.Connection.Execute strSql
但是嘗試從DAO觸發錯誤#3290 執行相同的語句「語法錯誤在CREATE TABLE語句」。 ...
CurrentDb.Execute strSql ' CurrentDb refers to a DAO Database object
這意味着如果你嘗試,因爲它使用DAO從查詢設計器執行該語句,你會得到同樣的錯誤。
如果你可以使用比CREATE VIEW
其他的東西,可以考慮使用CreateQueryDef
方法來創建與SQL語句SELECT
查詢......
strSql = "SELECT TripID, TripName, StartLocation, State, Distance, MaxGrpSize, Type, Season" & vbCrLf & _
"FROM Trip" & vbCrLf & _
"WHERE State = 'NH';"
CurrentDb.CreateQueryDef "NHTrips", strSql
Microsoft Access數據庫引擎不支持使用CREATE VIEW的,或任何DDL語句與非Microsoft Access數據庫引擎databases.https://msdn.microsoft.com/en-us/library/bb177895(v = office.12).aspx –