我正在尝试从子报表中删除一行(我的子报表使用了不同表中的不同列值)。但我的数据类型不匹配错误!
以下是我使用的代码:
CurrentDb.Execute "DELETE FROM StateBudget " & " WHERE S_ID = " & _
DLookup("ID", "States", "State='" & _
Me.subformStateBudget.Form.Recordset.Fields("State") & "'")
我认为 S_ID 是一个文本值,那么如何将DLookup值更改为字符串或文本?
答案 0 :(得分:1)
您不需要将DLookUp值更改为字符串,您需要将其作为字符串(引号)传递给SQL:
CurrentDb.Execute "DELETE FROM StateBudget " & " WHERE S_ID = """ & _
DLookup("ID", "States", "State='" & _
Me.subformStateBudget.Form.Recordset.Fields("State") & "'") & """"