2

如果条件与 DataSelect 表匹配,我正在尝试执行一个循环,该循环将使用表 DataSelect 中的源代码更新表 Cleaned。标准的示例就像年份在 2012 年和 2011 年之间,频道就像TM和 MRC 介于 5 和 10 之间。我创建 DataSelect 来保存所有不同类型的标准,我希望程序循环遍历每个分配的标准清理了源代码。到目前为止,我总是收到“参数太少。预期 1。运行时错误 3061。” 任何帮助将不胜感激。

谢谢,尼基

Private Sub doDataSegm_Click()


Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL, strSearch, strReplace As String

Set db = CurrentDb()
Set rs = db.OpenRecordset("dataselect", dbOpenTable)

If rs.RecordCount = 0 Then Exit Sub
rs.MoveFirst

    For i = 1 To rs.RecordCount
    strChan = rs("Chan")
    strDataCode = rs("code")
    strMrcYrLow = rs("mrcyr_low")
    strMrcYrhigh = rs("mrcyr_high")
    strMrcLow = rs("mrc_low")
    strMrchigh = rs("mrc_high")
    strSQL = "UPDATE Cleaned SET [cleaned].[datacode]= " & _
              strDataCode & " where [CLEANED].[CHANNEL] Like '" & strChan & _
             "' AND [CLEANED].[MRC_YEAR] Between '" & strMrcYrLow & _
             "' And '" & strMrcYrhigh & "' AND CLEANED.MRC Between " & _
              strMrcLow & " And " & strMrchigh & ";"

    db.Execute strSQL, dbFailOnError
    rs.MoveNext
    Next i


End Sub
4

1 回答 1

0

类似“参数太少。预期 1。运行时错误 3061”之类的消息。通常表示您的查询包含未引用的数据值,Access 将其解释为字段名称。由于您的查询中唯一未加引号的标识符是datacodeand MRC,因此您似乎需要引用其中一个:

UPDATE Cleaned SET [Cleaned].[datacode] = '" & strDataCode & "' ...
                                          ^ ...add quotes...  ^
于 2012-04-04T21:33:18.417 回答