Me.Undo problem - no current record

Bruce75

Psychologist
Local time
Today, 23:41
Joined
Sep 29, 2004
Messages
46
hi

I have a little bit of code that uses a DLookup to prevent users from entering duplicate values, as below:

Private Sub groupIDFK_BeforeUpdate(Cancel As Integer)
justchosen = Me.groupIDFK
previouschosen = DLookup("groupIDFK", "jun_groupevent", "patientIDFK=[forms]![frm_patientdetails].[patientID] And groupIDFK=[forms]![frm_patientdetails].[sf_jun_groupevent].[form]![groupIDFK]")
If justchosen = previouschosen Then
MsgBox ("This patient is already recorded as a member of this group")
Cancel = True
Me.Undo
Me.Requery
Else

End If




End Sub

The code works insofar as it is able to tell if the duplication has occurred, and the duplicate value as undone as a result. However, after it does this it comes up with the error "No current record". Any ideas what I am doing wrong? As always, any help greatly appreciated.

cheers,

Bruce
 
Comment out the:
'-- Me.Undo
'-- Me.Requery
...and see if you like the way it runs.
 
thanks.

i did that, now it comes up with a different error:

"The value violates the validation rule for the field or record."

Not sure how I am violating a valdidation rule if i am not entering any data. Any ideas?
 
Cancel = True will hold the cursor in that control. What validation do you have in the field at the table level?
 
resolved problem by putting the code in the after_update event

not sure why that worked, but happy it did!
 

Users who are viewing this thread

Back
Top Bottom