Microsoft Access VBA错误461

时间:2015-06-18 15:30:01

标签: vba ms-access access-vba ms-access-2010

我无法弄清楚为什么我一直收到错误#461,"找不到方法或数据成员"

Private Sub cmdUpdate_Click()
    CurrentDb.Execute "UPDATE Parts " _
        & "SET [In-Week 1] = " & Me.in1 & ", [In-Week 2] = " & Me.in2 & ", [In-Week 3] = " & Me.in3 _
        & ", [In-Week 4] = " & Me.in4 & ", [In-Week 5] = " & Me.in5 & ", [In-Week 6] = " & Me.in6 & ", [In-Week 7] = " & Me.in7 _
        & ", [In-Week 8] = " & Me.in8 & ", [In-Week 9] = " & Me.in9 & ", [In-Week 10] = " & Me.in10 & ", [In-Week 11] = " & Me.in11 _
        & ", [In-Week 12] = " & Me.in12 & ", [In-Week 13] = " & Me.in13 & ", [In-Week 14] = " & Me.in14 & ", [In-Week 15] = " & Me.in15 _
        & ", [In-Week 16] = " & Me.in16 & ", [In-Week 17] = " & Me.in17 & ", [In-Week 18] = " & Me.in18 & ", [In-Week 19] = " & Me.in19 _
        & ", [In-Week 20] = " & Me.in20 & ", [In-Week 21] = " & Me.in21 & ", [In-Week 22] = " & Me.in22 & ", [In-Week 23] = " & Me.in23 _
        & ", [In-Week 24] = " & Me.in24 & ", [In-Week 25] = " & Me.in25 & ", [In-Week 26] = " & Me.in26 & ", [In-Week 27] = " & Me.in27 _
        & ", [In-Week 28] = " & Me.in28 & ", [In-Week 29] = " & Me.in29 & ", [In-Week 30] = " & Me.in30 & ", [In-Week 31] = " & Me.in31 _
        & ", [In-Week 32] = " & Me.in32 & ", [In-Week 33] = " & Me.in33 & ", [In-Week 34] = " & Me.in34 & ", [In-Week 35] = " & Me.in35 _
        & ", [In-Week 36] = " & Me.in36 & ", [In-Week 37] = " & Me.in37 & ", [In-Week 38] = " & Me.in38 & ", [In-Week 39] = " & Me.in39 _
        & ", [In-Week 40] = " & Me.in40 & ", [In-Week 41] = " & Me.in41 & ", [In-Week 42] = " & Me.in42 & ", [In-Week 43] = " & Me.in43 _
        & ", [In-Week 44] = " & Me.in44 & ", [In-Week 45] = " & Me.in45 & ", [In-Week 46] = " & Me.in46 & ", [In-Week 47] = " & Me.in47 _
        & ", [In-Week 48] = " & Me.in48 & ", [In-Week 49] = " & Me.in49 & ", [In-Week 50] = " & Me.in50 & ", [In-Week 51] = " & Me.in51 & ", [In-Week 52] = " & Me.in52 & "  " _
        & "WHERE [Part #] = '" & txtFindPart & "';"

点击我的按钮后,它会运行错误,并以黄色突出显示Private Sub cmdUpdate_Click(),并在正常光标突出显示中突出显示.in4

我确保所有部件都正确输入,并且它们以链接到VBA脚本的形式存在。

1 个答案:

答案 0 :(得分:1)

似乎Access与构建怪异UPDATE字符串的代码混淆了。当真正的问题是Me.in4不存在时,它抱怨Me.in5。当您检查您认为名为 in5 的文本框时,您会发现其名称实际上是 Text10in5

我通过将此代码添加到 cmdUpdate_Click()的开头来跟踪问题。当 i = 5时,第一个版本引发了错误,因此我将该值放在Case语句中以忽略它,并查看是否有任何剩余值引发类似错误。没有其他值引发错误。

Dim i As Long
For i = 1 To 52
    Select Case i
    Case 5
        ' pass: Text10in5
    Case Else
        Debug.Print Me.Controls("in" & i).Name
    End Select
Next

虽然这是一种有用的调试技术,但我向您展示的实际原因是因为我认为您应该使用类似的策略来更新 Parts 。使用目标部件行打开DAO.Recordset。然后遍历这52个文本框并将其值存储到相应的 Parts 字段...

For i = 1 To 52
    rs.Fields("In-Week " & i).Value = Nz(Me.Controls("in" & i).Value, 0)
Next

假设您将 Text10in5 重命名为 in5 ,那应该可以。