Can't open Recordset...

M

Meilu

I don't know why I can't open a recordSet.

I want to open a recordSet so I can access a value and set
a field in my form equal to that value.

Below is my Code. There are no compiler errors ... only
run time erros ... something about parameters not being
correct... (It's in chinese so I can't fully understand
the error message... )

Private Sub Product_AfterUpdate()
Dim db As Database
Dim rec As Recordset
Dim strQry As String

strQry = "Select Price " & _
" From SupplierProduct " & _
" WHERE EntityName = " & Me!Vendor & " AND
Product = " & Me!Product


Set db = CurrentDb()
Set rec = db.OpenRecordset(strQry, dbOpenDynaset) <--
this is where the error is!
Me!Cost = rec!Price


End Sub

Is it possible that the qry is wrong? Because I used the
same exact code to do something similiar ... and it works
just fine!

Any help would be greatly appreciated!
Meilu
 
L

Larry Linson

Chances are, a Field called "somethingName" is a text field and the
value supplied in the WHERE clause needs to be enclosed in quotes, as

strQry = "Select Price " & _
" From SupplierProduct " & _
" WHERE EntityName = """ & Me!Vendor & _
""" AND Product = " & Me!Product

If the Product Field is also text, it should read

strQry = "Select Price " & _
" From SupplierProduct " & _
" WHERE EntityName = """ & Me!Vendor & _
""" AND Product = """ & Me!Product & """"

Larry Linson
Microsoft Access MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top