访问存储过程不起作用

时间:2015-06-30 13:05:35

标签: ms-access access-vba

以下存储过程不起作用,我已经尝试了一切但没有成功。请帮忙。

Sub Create_View()

    Dim conn As ADODB.Connection

    Set conn = Application.CurrentProject.Connection

    conn.Execute "CREATE VIEW vw_RobPS AS " & _
    "SELECT sid, " & _
    "Lname, " & _
    "Fname, " & _
    "EmpStatus, " & _
    "[Peax Update as of 6-18-15], " & _
    "[Peax Update Date] " & _
    "FROM Master_06-18-2015" & _
    "WHERE [Peax Update Date] as PeaxUdDt is not null; "

    Application.RefreshDatabaseWindow

ExitHere:
  If Not conn Is Nothing Then
    If conn.State = adStateOpen Then conn.Close
  End If

    Set conn = Nothing
End Sub

当我运行它时,我收到此错误消息:

  

运行时错误'-2147217900(80040e14)':FROM子句中的语法错误。

我找不到问题。

1 个答案:

答案 0 :(得分:6)

  1. 您的表名包括破折号;将该名称括在方括号中
  2. 在表名与WHERE
  3. 之间加一个空格
  4. 请勿尝试在WHERE子句
  5. 中为字段设置别名
    "FROM [Master_06-18-2015] " & _
    "WHERE [Peax Update Date] is not null; "