Access supports CREATE VIEW when executed from ADO / OleDb. This piece of code works because CurrentProject.Connection is an ADO object ...
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
However, an attempt to execute the same instruction from triggers DAO # 3290 "Syntax error in the CREATE TABLE statement" ....
CurrentDb.Execute strSql ' CurrentDb refers to a DAO Database object
This means that you will get the same error if you try to execute this statement from the query designer, since it uses the DAO.
If you can use something other than CREATE VIEW , consider the CreateQueryDef method to create a query using the SQL SELECT ...
strSql = "SELECT TripID, TripName, StartLocation, State, Distance, MaxGrpSize, Type, Season" & vbCrLf & _ "FROM Trip" & vbCrLf & _ "WHERE State = 'NH';" CurrentDb.CreateQueryDef "NHTrips", strSql
source share