Microsoft Access VBA 运行 时间错误 2465
Microsoft Access VBA Run Time Error 2465
我目前正在制作一个表格来更新我数据库中的字段。按钮 (cmdFind) 用于查找部件号的记录(在文本框 txtFindPart 中输入),然后将数据填充到 In1-52 和 out1-52 中。当我 运行 我得到 Run-time Error 2465 Microsoft Access can not find the field '|1' referred to in your expression.
Private Sub cmdFind_Click()
Dim i As Integer
i = 1
If IsNull(txtFindPart) = False Then
If Me.Recordset.NoMatch Then
MsgBox "No record found", vbOKOnly + vbInformation, "Sorry"
Me!txtFindPart = Null
End If
Do Until i = 53
Me.Controls("in" & i) = DLookup("[In-Week " & i & "]", [Parts], "(([Parts].[Part #]) = '" & txtFindPart & "')")
Me.Controls("out" & i) = DLookup("[Out-Week " & i & "]", [Parts], "(([Parts].[Part #]) = '" & txtFindPart & "')")
i = i + 1
Loop
End If
End Sub
如有任何帮助,我们将不胜感激。
我发现问题是 table Parts
没有打开,这是导致错误的原因。我只需要添加一行来打开 table 并在最后关闭它。
DoCmd.OpenTable "Parts"
Dim i As Integer
i = 1
If IsNull(txtFindPart) = False Then
If Me.Recordset.NoMatch Then
MsgBox "No record found", vbOKOnly + vbInformation, "Sorry"
Me!txtFindPart = Null
End If
Do Until i = 53
Me.Controls("in" & i) = DLookup("[In-Week " & i & "]", "[Parts]", "(([Parts].[Part #]) = '" & txtFindPart & "')")
Me.Controls("out" & i) = DLookup("[Out-Week " & i & "]", "[Parts]", "(([Parts].[Part #]) = '" & txtFindPart & "')")
i = i + 1
Loop
End If
DoCmd.Close , "Parts"
我目前正在制作一个表格来更新我数据库中的字段。按钮 (cmdFind) 用于查找部件号的记录(在文本框 txtFindPart 中输入),然后将数据填充到 In1-52 和 out1-52 中。当我 运行 我得到 Run-time Error 2465 Microsoft Access can not find the field '|1' referred to in your expression.
Private Sub cmdFind_Click()
Dim i As Integer
i = 1
If IsNull(txtFindPart) = False Then
If Me.Recordset.NoMatch Then
MsgBox "No record found", vbOKOnly + vbInformation, "Sorry"
Me!txtFindPart = Null
End If
Do Until i = 53
Me.Controls("in" & i) = DLookup("[In-Week " & i & "]", [Parts], "(([Parts].[Part #]) = '" & txtFindPart & "')")
Me.Controls("out" & i) = DLookup("[Out-Week " & i & "]", [Parts], "(([Parts].[Part #]) = '" & txtFindPart & "')")
i = i + 1
Loop
End If
End Sub
如有任何帮助,我们将不胜感激。
我发现问题是 table Parts
没有打开,这是导致错误的原因。我只需要添加一行来打开 table 并在最后关闭它。
DoCmd.OpenTable "Parts"
Dim i As Integer
i = 1
If IsNull(txtFindPart) = False Then
If Me.Recordset.NoMatch Then
MsgBox "No record found", vbOKOnly + vbInformation, "Sorry"
Me!txtFindPart = Null
End If
Do Until i = 53
Me.Controls("in" & i) = DLookup("[In-Week " & i & "]", "[Parts]", "(([Parts].[Part #]) = '" & txtFindPart & "')")
Me.Controls("out" & i) = DLookup("[Out-Week " & i & "]", "[Parts]", "(([Parts].[Part #]) = '" & txtFindPart & "')")
i = i + 1
Loop
End If
DoCmd.Close , "Parts"