Dlookup - Automation Error ?

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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
 
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.
 
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
 
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.
 
Back
Top