0

Microsoft Access 2010 数据库给我以下错误消息:

Compile Error: Expected End Of Statement  

这是引发错误消息的方法:

Private Sub Form_BeforeUpdate(Cancel As Integer)
    'Provide the user with the option to save/undo
    'changes made to the record in the form
    If MsgBox("Changes have been made to this record." _
        & vbCrLf & vbCrLf & "Do you want to save these changes?" _
        , vbYesNo, "Changes Made...") = vbYes Then
            DoCmd.Save
        Else
            DoCmd.RunCommand acCmdUndo
    End If

    Dim sSQL As String
    sSQL = "SELECT max(Clients.ClientNumber) AS maxClientNumber FROM Clients"
    Dim rs As DAO Recordset
    Set rs = CurrentDb.OpenRecordset(sSQL)
    MsgBox ("Max client number is: " & rs.Fields(1))
End Sub  

抛出错误消息的代码行是:

 Dim rs As DAO Recordset  

我不确定问题是否与前一行的语法有关。谁能展示如何解决这个问题?并解释发生了什么?

4

2 回答 2

3

DAO您在 the和 the之间缺少一个句号(句点)Recordset- 它应该是

Dim rs As DAO.Recordset

除此之外,在读取字段值时还会出现运行时错误,因为 DAO Fields 集合的索引是从 0 开始,而不是 1。因此,将倒数第二行更改为:

MsgBox ("Max client number is: " & rs.Fields(0))

或者,通过其名称引用该字段:

MsgBox ("Max client number is: " & rs!maxClientNumber)
于 2013-10-23T01:23:33.920 回答
0

您在 Sql 语句末尾缺少分号

于 2013-10-24T00:28:24.497 回答