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
我不确定问题是否与前面的行的语法有关。任何人都可以展示如何解决这个问题?并解释发生了什么?
答案 0 :(得分:3)
您错过了DAO
和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)
答案 1 :(得分:0)
你在Sql语句结束时使用分号