1
Dim rs As DAO.Recordset

sSQL = "SELECT Stock, Scanned FROM Products&
WHERE ((([Stock])=Forms!Products![StockCode]))                                                
And ((([Scanned])=Forms!Products![Scanned Information]));"

Set rs = CurrentDb.OpenRecordset(sSQL)

If rs.RecordCount = 0 Then
MsgBox "This is not correct"
Else
MsgBox "wooooo this works"
End If

我知道我的 SQL 查询是错误的,但我不确定如何正确地构造它并且我不断收到错误。我是否想用更多的引号将其Forms!Products![StockCode]分开并将逗号放在外面?

4

1 回答 1

2

您认为需要用引号将其添加的想法是正确的。这应该适合你:

sSQL = "SELECT Stock, Scanned FROM Products " & _
        "WHERE  [Stock] = '" & Forms!Products![StockCode] &"' " & _                                              
        "AND    [Scanned] = '" & Forms!Products![Scanned Information] & "';"

Set rs = CurrentDb.OpenRecordset(sSQL)

注意我已经删除了你所有的括号,它们是多余的,((1)=(1))意思完全一样1=1

于 2013-06-24T08:37:20.667 回答