VBA and logic help

J

Junior

in Beforeupdate in a bound cbobox
I want to test if the bound table already contains a value -
if doesn't contains a value, i want to allow the update
If the table already contains a value <> the update , i want to cancel the
update
and take other action
Please help with the VBA to find the correct record using DLookup
AppID and txtAppID are both numerical

Dim strOldPos As String
strOPos = DLookup("AppPosition", "TblApp") Where TblApp.AppId =
"Me.txtAppID"
 
R

Ricky Hicks MVP

You need to use DCount() instead of DLookup() ...
If the return of the DCount() is greater than 0 .. then the value exists in
the table and you can invoke the Cancel argument of the Before Update event
of the control ...

Personally .. I think I would use the FindFirst method to locate any
duplicate entries ...

R. Hicks
 
Top