Dlookup - Automation Error ?

G

Guest

Hi there, I have this simple D lookup to try and get the costs to assign to a
field in a record.
dim findcost as currency
findcost = DLookup("curCost", "tblproducts", "stritem = " & Me.strItem)
I get Run Time error 2471, object doesnt contain automation object 'Parka."
(parka being the Item selected on the form which I am trying to get a cost
for )

Can anyone help me with this ? I dont see where I am going wrong.
Todd
 
G

Guest

If me.strItem is a string, then you need to redo the last part of your dlookup:

findcost = DLookup("curCost", "tblproducts", "stritem = '" & Me.strItem & "'")

Looks like me.strItem is a string. I don't know off the top of my head if
this can cause the error you mentioned, but I thought I would throw it out
there.

HTH,
Clint Herman
 
A

Allan Murphy

Todd

Is stritem a field name in your table or is PARKA the field name?

In last part of the Dlookup stritem = , stritem must be the field name in
your table that will be used to lookup the value of your item selected.
 
G

Guest

Worked. Thanks SO much.
Todd

cherman said:
If me.strItem is a string, then you need to redo the last part of your dlookup:

findcost = DLookup("curCost", "tblproducts", "stritem = '" & Me.strItem & "'")

Looks like me.strItem is a string. I don't know off the top of my head if
this can cause the error you mentioned, but I thought I would throw it out
there.

HTH,
Clint Herman
 
G

Guest

Worked for now, but you are leaving a big hole for an error here. If the
DLookup function does not get a match, it returns Null. The only variable
type that can receive a Null is Variant. Either re-type findcost as Variant
or use the Nz() function to avoid getting an error "Invalid Use of Null"

findcost = Nz(DLookup("curCost", "tblproducts", "stritem = '" & Me.strItem &
"'"),0)

Now, if DLookup does not find a match, the Nz will replace Null with 0 and
findcost will not have a problem.
 

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

Access Can't Get Dlookup To Work 1
dlookup 2
Dlookup problems (was my Dlookup hell) 3
Error 2471 11
Error 2471 10
Help with DLookup 4
DLookup error 1
Dlookup and format 2

Top