S
Slez via AccessMonster.com
I'm trying to add records to a subform and store a value in a particular
field, just like in the Northwind database Order Details form. The purpose
is to store the value in my field UnitCost from the Product table into the
UnitPrice field of the ItemDetail table when the ProductDescription is
selected in my subform. To accomplish this, I added an AfterUpdate event to
the ProductDescription control. I pasted the following code from Northwind
and adapted to my database' field and table names:
Private Sub ProductDescription_AfterUpdate()
On Error GoTo Err_ProductDescription_AfterUpdate
Dim strFilter As String
' Evaluate filter before it's passed to DLookup function.
strFilter = "ProductDescription = " & Me!ProductDescription
' Look up product's unit price and assign it to UnitPrice control.
Me!UnitPrice = DLookup("UnitCost", "Product", strFilter)
Exit_ProductDescription_AfterUpdate:
Exit Sub
Err_ProductDescription_AfterUpdate:
MsgBox Err.Description
Resume Exit_ProductDescription_AfterUpdate
End Sub
However, I am getting the following message when a new record is added to
the subform:
Syntax error (missing operator) in query expression 'ProductDescription =
Base.3 drawer'
Where Northwind has a ProductID, I have ProductDescription, which is a text
field. Perhaps that has something to do with the error. In the error
message, "Base.3 drawer" happens to be the product I picked to try this out.
UnitPrice is the field in the table ItemDetail to store the value.
UnitCost is the value I'm pulling in from the table Product.
As mentioned, is the fact that ProductID in Northwind is a Long Integer and
my ProductDescription is a text field causing the problem? If so, how do I
correct my expression?
I would greatly appreciate any assistance!
Slez
field, just like in the Northwind database Order Details form. The purpose
is to store the value in my field UnitCost from the Product table into the
UnitPrice field of the ItemDetail table when the ProductDescription is
selected in my subform. To accomplish this, I added an AfterUpdate event to
the ProductDescription control. I pasted the following code from Northwind
and adapted to my database' field and table names:
Private Sub ProductDescription_AfterUpdate()
On Error GoTo Err_ProductDescription_AfterUpdate
Dim strFilter As String
' Evaluate filter before it's passed to DLookup function.
strFilter = "ProductDescription = " & Me!ProductDescription
' Look up product's unit price and assign it to UnitPrice control.
Me!UnitPrice = DLookup("UnitCost", "Product", strFilter)
Exit_ProductDescription_AfterUpdate:
Exit Sub
Err_ProductDescription_AfterUpdate:
MsgBox Err.Description
Resume Exit_ProductDescription_AfterUpdate
End Sub
However, I am getting the following message when a new record is added to
the subform:
Syntax error (missing operator) in query expression 'ProductDescription =
Base.3 drawer'
Where Northwind has a ProductID, I have ProductDescription, which is a text
field. Perhaps that has something to do with the error. In the error
message, "Base.3 drawer" happens to be the product I picked to try this out.
UnitPrice is the field in the table ItemDetail to store the value.
UnitCost is the value I'm pulling in from the table Product.
As mentioned, is the fact that ProductID in Northwind is a Long Integer and
my ProductDescription is a text field causing the problem? If so, how do I
correct my expression?
I would greatly appreciate any assistance!
Slez