使用Dlookup语法错误访问VBA Findfirst

时间:2018-03-21 10:10:45

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

我在这段代码中遇到错误语法错误(缺少运算符)

For i = 0 To Me.listMachineSubSystem.ListCount - 1
    rs.FindFirst "[Machine ID]=" & ID & "[MachineSystem]=" & DLookup("[MachineSystem]", "tblMachineSystem", "[Machine System ID]=" & Me.listMachineSubSystem.Column(2, i))

   rs1.AddNew
   rs1![MachineSubsystem] = Me.listMachineSubSystem.Column(1, i)
   rs1![Machine Sytem ID] = rs![Machine System ID]
   rs1.Update
 Next i

1 个答案:

答案 0 :(得分:2)

您需要考虑间距,在检查多个条件时使用AND关键字,并在需要时使用分隔符(字符串)。

如果MachineSystem是数字:

rs.FindFirst "[Machine ID]= " & ID & " AND [MachineSystem]=" & DLookup("[MachineSystem]", "tblMachineSystem", "[Machine System ID]=" & Me.listMachineSubSystem.Column(2, i))

如果MachineSystem是字符串:

rs.FindFirst "[Machine ID]= " & ID & " AND [MachineSystem]= '" & DLookup("[MachineSystem]", "tblMachineSystem", "[Machine System ID]=" & Me.listMachineSubSystem.Column(2, i)) & "'"