【问题标题】:access error 3061 Too Few parameters expected 1访问错误 3061 期望的参数太少 1
【发布时间】:2017-02-14 17:10:41
【问题描述】:

帮助!我在数据库上的访问代码遇到了一些问题,它说访问错误 3061 Too Few parameters expected 1. 突出显示的问题是

Set oRS = CurrentDb.OpenRecordset(sSQL)

    Dim i As Date, n As Integer, oRS As DAO.Recordset, sSQL As String

Dim db As DAO.Database
Set db = CurrentDb
Dim BookedDate As Date
Dim FacilitiesID As String
Dim StartTime As Date

cboTime.RowSourceType = "Value List"
cboTime.RowSource = ""
If IsNull(Start) Then Exit Sub Else i = Start
If Me.NewRecord = True Then
    DoCmd.RunCommand acCmdSaveRecord
End If
sSQL = "SELECT FacilitiesID, StartTime, BookedDate"
sSQL = sSQL & " FROM qrysubform"
sSQL = sSQL & " WHERE FacilitiesID= " & Me.FacilitiesID & _
                        " AND BookedDate=# " & Me.txtDate & "#"
Set oRS = CurrentDb.OpenRecordset(sSQL)

【问题讨论】:

    标签: ms-access vba


    【解决方案1】:

    您的设施 ID 被标注为一个字符串,但在您的 SQL 语句中它被引用为一个数字。如果您的表单的 FacilitiesID 实际上是一个字符串,则需要将其括在引号中:

    sSQL = "SELECT FacilitiesID, StartTime, BookedDate"
    sSQL = sSQL & " FROM qrysubform"
    sSQL = sSQL & " WHERE FacilitiesID= '" & Me.FacilitiesID & _
                            "' AND BookedDate=#" & Me.txtDate & "#"
    

    【讨论】:

      【解决方案2】:

      在这种情况下,插入 debug 行并研究输出:

      Debug.Print sSQL
      ' Study output
      Set oRS = CurrentDb.OpenRecordset(sSQL)
      

      也就是说,此错误通常是由缺少或拼写错误的字段名称引起的。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-04-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-07-23
        • 1970-01-01
        相关资源
        最近更新 更多