problem by using runsql in access 2010

bill201
bill201 used Ask the Experts™
on
i have a code that have to run a query and check if in the qury value is higher then 1 one and if is truh that i have to get an message and there is my code:
<Dim b
b = DoCmd.RunSQL("SELECT Count(InvoiceT.Price) AS CountOfPrice " & _
                    "FROM InvoiceT " & _
                    "GROUP BY InvoiceT.Product " & _
                    "HAVING Product =" & Me.ListProducts.Column(1))
If b > 1 Then MsgBox "There is not matching pricse">


but i get an error message that point on the "runsql" :Compile error:
Expected Function or variable
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016
Commented:
with that select statement, you need to open it as  recordset or use dcount

if dcount("[Price]","InvoiceT","Product=" & me.listproducts.column(1))> 1 then
  'message here

end if

if Product is text use this

if dcount("[Price]","InvoiceT","Product='" & me.listproducts.column(1) & "'")> 1 then
  'message here

end if

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial