Check for duplicate record from many to many table - numeric


/ Published in: Visual Basic
Save to your folder(s)



Copy this code and paste it in your HTML
  1. Private Sub ABID_AfterUpdate()
  2. On Error GoTo Err_Handler
  3.  
  4. Dim rsc As DAO.Recordset
  5. Set rsc = Me.RecordsetClone
  6.  
  7. 'Check table for duplicate
  8. If DCount("ABID", "tblAntibioticsSubjects", "ABID=" & Me.ABID & " AND SubjectID = " & Me.SubjectID) > 0 Then
  9. 'Undo duplicate entry
  10. Me.Undo
  11. 'Message box warning of duplication
  12. MsgBox "This antibiotic has already been selected for this patient.", vbInformation, "Duplicate Antibiotic"
  13. End If
  14.  
  15. Set rsc = Nothing
  16.  
  17. Exit_Handler:
  18. Exit Sub
  19. Err_Handler:
  20. If Err.Number = 94 Then
  21. ' Invalid use of Null error
  22. Resume Exit_Handler
  23. Else
  24. End If
  25.  
  26. End Sub

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.