SOS with references in subform!!!

mihalisp

Registered User.
Local time
Yesterday, 21:53
Joined
Oct 19, 2009
Messages
27
Hi everybody,i would be grateful if someone could help me on this:

I have the following code to prevent duplicate records

Private Sub ypothesi_id_AfterUpdate()
Dim SID As String
Dim stLinkCriteria As String
Dim rsc As DAO.Recordset

Set rsc = Me.RecordsetClone

SID = Me.ypothesi_id.Value
stLinkCriteria = "[ypothesi_id]=" & "'" & SID & "'"

'Check StudentDetails table for duplicate StudentNumber
If DCount("ypothesi_id", "status_energeiwn", _
stLinkCriteria) > 0 Then
'Undo duplicate entry
Me.Undo
'Message box warning of duplication
MsgBox "Warning Student Number " _
& SID & " has already been entered." _
& vbCr & vbCr & "You will now been taken to the record.", _
vbInformation, "Duplicate Information"
'Go to record of original Student Number
rsc.FindFirst stLinkCriteria
Me.Bookmark = rsc.Bookmark
End If

Set rsc = Nothing
End Sub

The code above works for the form itself,but i use this form as a subform in another form called Client_form.So when i am in the Client_form this code doesnt work ,probably because of the wrong references i use inside the vba code,right?

Can anyone help me with the correct references because i am so confused with these references.Should all the "Me" references change?

Thank you in advance!
 
Stopping duplicates should be accomplished in BeforeUpdate events and not AfterUpdate events. You can cancel the BeforeUpdate event. Also Me.UnDo can not do anything *after* the record has been saved. If it is just one field that you are checking for duplicates then do the checking in the BeforeUpdate event of *that* control and not the FORM event.
 
Last edited:
Thanks,but you dont tell me something new.
I know that i should write the beforeupdate event of the ypothesi_id txtbox,it was my mistake to type afterupdate.

It is one field i want to prevent duplicates into and i use the beforeupdate event of that control not the form's event.

i dont know how to type the correct references,nothing else.
 
I think that the lines of code that should change are the following:

1)Set rsc = Me.RecordsetClone

2)SID = Me.ypothesi_id.Value

3)Me.Undo

4)Me.Bookmark = rsc.Bookmark

where the ypothesi_id is the txtbox in the subform of the Client_form(main form)
Please can someone help?
 

Users who are viewing this thread

Back
Top Bottom