Results 1 to 2 of 2
  1. #1
    Kananelo is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2011
    Posts
    7

    Angry Duplicate data entry on form level by user

    Good day folks

    I need your help if you may. I have a database with a form bound to a table Patients. I use this form to capture patient information. I have added some code to the beforeUpdate event of the form to prompt the user if the record being entered already exist in the database with the option to view the original record, carry on adding or cancel adding altogether. It works fairly well except for the part where it has to take me to the form to view the original record. It gives me run-time error 3024 (Object Ivalid or no longer set)then highlights the "rsc.FindLast Criteria" part. Code is attached.



    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
        Dim PID As String
        Dim Criteria As String
        Dim fAns As Integer
        Dim rsc As DAO.Recordset
            
            Set rsc = Me.RecordsetClone
            PID = Me.First_Name.Value
            
            Criteria = "[First_Name]=" & "'" & PID & "'"
            
            If DCount("*", "Patients", Criteria) > 0 Then
                fAns = MsgBox("This Record Already Exists! Add it Anyway?" _
                        & vbCrLf & "Click Yes to add, No to jump to existing record, " _
                        & vbCrLf & "Cancel to go back to editing this record", _
                            vbYesNoCancel)
            Select Case fAns
            Case vbYes ' do nothing, let the record be added
            
            Set rsc = Nothing
                If MsgBox("You are about to add a record." _
                    & vbCrLf & vbCrLf & "Do you want to save this record?" _
                    , vbYesNo, "Record Confirmation") = vbYes Then
                
                DoCmd.Save
            Else
                DoCmd.RunCommand acCmdUndo
        End If
            Case vbNo
    Cancel = True
                Me.Undo
                rsc.FindLast Criteria
                Me.Bookmark = rsc.Bookmark ' move to last found record
            Case vbCancel
    Cancel = True ' suppress update, return to form
    End Select
    End If
    End Sub

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Try:

    Remove the Set rsc = Nothing

    Set the recordset just before the FindLast

    If that works it will tell you somewhere above the FindLast the recordset was closing, although I can't see why.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 13
    Last Post: 11-18-2013, 02:20 PM
  2. Replies: 1
    Last Post: 12-15-2011, 04:26 AM
  3. Replies: 1
    Last Post: 08-13-2011, 04:44 AM
  4. Replies: 8
    Last Post: 06-30-2010, 10:57 PM
  5. Replies: 3
    Last Post: 06-04-2010, 12:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums