Attempting CREATE VIEW in Access gives “Syntax error in CREATE TABLE statement”

一曲冷凌霜 提交于 2019-11-29 15:10:24

Access supports CREATE VIEW when you execute it from ADO/OleDb. This code snippet 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 attempting to execute the same statement from DAO triggers error #3290 "Syntax error in CREATE TABLE statement." ...

CurrentDb.Execute strSql ' CurrentDb refers to a DAO Database object

That means you will get the same error if you attempt to execute that statement from the query designer because it uses DAO.

If you can use something other than CREATE VIEW, consider using the CreateQueryDef method to create your query with the SQL SELECT statement ...

strSql = "SELECT TripID, TripName, StartLocation, State, Distance, MaxGrpSize, Type, Season" & vbCrLf & _
    "FROM Trip" & vbCrLf & _
    "WHERE State = 'NH';"
CurrentDb.CreateQueryDef "NHTrips", strSql

Not much info given about which database you are trying to create a view in. If you are trying to create a view in access, then you should think of all the queries that are in the navigation bar of access as VIEWS.

These can be created using VBA by manipulating the QueryDefs object see here and here

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!