This Record Already Exist? [Resolved]
Why am I getting a "This Record Already Exist" error when I am just doing a query?
Why am I getting a "This Record Already Exist" error when I am just doing a query?
Code:
'This query works prefectly and I get the results I want.
sSQLQuery = "SELECT * FROM Prices WHERE KitchenID = '" & txtKitchenID _
& "' AND [Customer ID] = '" & txtCustomer _
& "' AND [Bill Code] = '" & cmbBillCode & "' ORDER BY [Effective Date]"
If rsPrice.State = adStateOpen Then
rsPrice.Close
End If
rsPrice.CursorType = adOpenStatic
rsPrice.LockType = adLockReadOnly
rsPrice.Source = sSQLQuery
rsPrice.Open
'Then I go and do this query and it blows up when it gets to
'rs.open.
sSQLQuery = "SELECT DISTINCT [Price Type] FROM Prices WHERE KitchenID = '" & txtKitchenID _
& "' AND [Customer ID] = '" & txtCustomer _
& "' AND [Bill Code] = '" & cmbBillCode _
& "' AND [Price Type] <> '' ORDER BY [Effective Date]"
If rs.State = adStateOpen Then
rs.Close
End If
rs.CursorType = adOpenStatic
rs.LockType = adLockReadOnly
rs.Source = sSQLQuery
rs.Open
'I tried doing this and it still errors.
sSQLQuery = "SELECT DISTINCT [Price Type] FROM Prices WHERE KitchenID = '" & txtKitchenID _
& "' AND [Customer ID] = '" & txtCustomer _
& "' AND [Bill Code] = '" & cmbBillCode "'"
'I also tried this and it errors as well
sSQLQuery = "SELECT DISTINCT [Price Type] FROM Prices WHERE KitchenID = '" & txtKitchenID _
& "' AND [Customer ID] = '" & txtCustomer _
& "' AND [Price Type] <> '' ORDER BY [Effective Date]"
'But when I do this, it works fine.
sSQLQuery = "SELECT DISTINCT [Price Type] FROM Prices WHERE KitchenID = '" & txtKitchenID _
& "' AND [Customer ID] = '" & txtCustomer & "'"
'so I am guessing it has a problem with the last two lines
'but I don't see what.
Last edited: