Undo DLookup?

gMAC

Registered User.
Local time
Today, 22:40
Joined
Dec 21, 2001
Messages
29
I built a form (Access97) with date fields and part number fields. When a part has been replaced in the equipment, I need to track the expense. To simplify data entry I used Dlookup (After Update) to lookup a price from a parts price table. This works great, but my problem is if someone enters a date by mistake and then deletes the date, the price is still in the table.

Sample of code:
txboxDate Field-After Update

If (Me!TypeOfPart = A) Then
txboxPrice = DLookup("[fldPartPrice]", "tblPartA", "[fldPrtNo] = '" & Me!PartNo & "'")
Else
If (Me! TypeOfPart = B) Then
txboxPrice = DLookup("[fldPartPrice]", "tblPartB", "[fldPrtNo] = '" & Me! PartNo & "'")
Else
If (Me! TypeOfPart = C) Then
txboxPrice = DLookup("[fldPartPrice]", "tblPartC", "[fldPrtNo] = '" & Me! PartNo & "'")

(This is the part I’m having trouble with, what is the best method of returning the value to zero if the date is deleted.)
Else
If IsNull(Me!txboxDate) Or Me!txboxDate = "" Then
?????

End If
End If
End If
End if

I’ve just started learning VBA so baby steps please.
Thanks
Gary


[This message has been edited by gMAC (edited 02-02-2002).]
 
I assume that the price field is currency so Me![txboxPrice] = 0 should do the trick.
 
Thank for the reply Jack, you are correct, it is currency. Your suggestion was one of my first attempts, but the value in the price text box still did not change.
Any Ideas?

Gary
 
If 'txboxPrice' is a field on the current form then it should work. If you are trying to update a field in another table then you will need an Update query or code to change the value....
 
It started working. I did a compact and repair database, then it worked! Go figure.

Thanks for the help.
 

Users who are viewing this thread

Back
Top Bottom