Private Sub Form_BeforeUpdate(Cancel As Integer)
With Me.RecordsetClone
.FindFirst "UMRN = '" & Me!UMRN & "'"
Cancel = (.NoMatch = False)
If Cancel Then
MsgBox "UMRN already exists"
Me.UMRN.Undo
Me.Bookmark = .Bookmark
End If
End With
End Sub
Private Sub Form_BeforeUpdate(Cancel As Integer)
If DCount("*", "OrderDetails", "ProductID = " & Me.ProductID & " AND OrderID = " & Me.OrderID) > 0 Then
MsgBox "This Product already entered"
Cancel = True
Me.ProductID.SetFocus
Exit Sub
End If
End Sub
dear access family
i want some more feature.
this code is working fine
i want that after entring duplicate entry, and after msg box ok button clicked, the current entry cancelled and and previous entry of same product set focused.Code:Private Sub Form_BeforeUpdate(Cancel As Integer) If DCount("*", "OrderDetails", "ProductID = " & Me.ProductID & " AND OrderID = " & Me.OrderID) > 0 Then MsgBox "This Product already entered" Cancel = True Me.ProductID.SetFocus Exit Sub End If End Sub
View attachment 102857
how it could be possible in vba.
Thank youit's a Validation code (BeforeUpdate), so you cannot just leave the control/record it is validating (or setFocus on another control).
you need to complete the validation first.
Thanks, i was not aware,@accessonly11 Please do not hijack old threads to ask new questions. Start a NEW thread for each new question. If you want to refer to an existing thread, post a link.
The solution posted by @arnelgp is incomplete. There is no validation in the form's BeforeUpdate event so you can add rows without a ProductID.
and thanks to arnelgp and all of you, now this function is working after putting code given by arnelgpit's a Validation code (BeforeUpdate), so you cannot just leave the control/record it is validating (or setFocus on another control).
you need to complete the validation first.