Check for duplicate value (numeric)


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



Copy this code and paste it in your HTML
  1. Private Sub SubjectID_BeforeUpdate(Cancel As Integer)
  2. On Error GoTo Err_Handler
  3.  
  4. Dim SubID As String
  5. Dim stLinkCriteria As String
  6. Dim rsc As DAO.Recordset
  7.  
  8. Set rsc = Me.RecordsetClone
  9.  
  10. SubID = Me.SubjectID.Value
  11. stLinkCriteria = "[SubjectID]=" & SubID
  12.  
  13. 'Check table for duplicate
  14. If DCount("SubjectID", "tblSubjects", stLinkCriteria) > 0 Then
  15. 'Undo duplicate entry
  16. Me.Undo
  17. 'Message box warning of duplication
  18. MsgBox "The Subject ID " & SubID & " is already in use." & _
  19. Chr(13) & Chr(13) & "Please check to see if this patient has already been entered. " & _
  20. "If not, then assign the patient a Subject ID.", vbInformation, "Duplicate Subject ID"
  21. 'Go to the duplicate record
  22. 'rsc.FindFirst stLinkCriteria
  23. 'Me.Bookmark = rsc.Bookmark
  24. End If
  25.  
  26. Set rsc = Nothing
  27.  
  28. Exit_Handler:
  29. Exit Sub
  30. Err_Handler:
  31. If Err.Number = 94 Then
  32. ' Invalid use of Null error
  33. Resume Exit_Handler
  34. Else
  35. End If
  36. End Sub

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.