代码哪里错了啊

来源:百度知道 编辑:UC知道 时间:2024/05/08 17:01:46
Private Sub cmbname_Click()
Dim condition
condition = Trim(cmbfield.Text)
'去掉字符串前面和后面的空格
If Adodc1.Recordset.Fields(condition).Type = "202" Then
'被选择的类型如果为文本类型
Adodc1.RecordSource = "select * from 库存 where" & condition & " = '" & cmbname.Text & "'"
'被选择的字段类型如果是数值类型
Else
Adodc1.RecordSource = "select * from 库存 where" & condition & " = " & cmbname.Text
End If
Adodc1.Refresh
txtno.Text = Adodc1.Recordset.Fields("货物编号")
txtname.Text = Adodc1.Recordset.Fields("货物名称")
txtstorenum.Text = Adodc1.Recordset.Fields("库存量")
txtunit.Text = Adodc1.Recordset.Fields("单位")
End Sub

错误提示:From子句语法错误

"select * from 库存 where" & condition & " = '" & cmbname.Text & "'"

"select * from 库存 where" & condition & " = " & cmbname.Text
在 where后面要一个空格 不然拼出来的字符串里就不是from ... where ... 而成了 from ... whereXXXXX ...

where后面加空格