请大神帮忙看看这个异常什么意思

2026年09月18日 12:47
有1个网友回答
网友(1):

这句有问题>> sql = "select Item from SOP where VW_Code =Me!VW_Code"

如果SOP表的“VW_Code”字段的数据类型是数字,则应这样写
sql = "select Item from SOP where VW_Code =" Me.VW_Code

如果SOP表的“VW_Code”字段的数据类型是文本,则应这样写
sql = "select Item from SOP where VW_Code ='" Me.VW_Code "'"

另外,为了避免窗体控件VW_Code没有输入内容时代码运行出错,请添加下列代码。

A) SOP表的“VW_Code”字段的数据类型是数字时的处理方法:
'..
If Not IsNumeric(Me.VW_Code) then
Msgbox "请输入一个数字"
Me.VW_Code.SetFocus
Exit Sub
End If
sql = "select Item from SOP where VW_Code =" Me.VW_Code
'.

B) SOP表的“VW_Code”字段的数据类型是文本时的处理方法:
'..
If IsNull(Me.VW_Cod) then
Msgbox "VW_Code不得为空"
Me.VW_Code.SetFocus
Exit Sub
End If
sql = "select Item from SOP where VW_Code ='" Me.VW_Code "'"
'.

如还有不明白,请发会问。