Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2008

    Unanswered: Finiky code or haunted!

    I have a code that seems to work randomly, sometimes ? For example, every time I test the code it works fine but still when I check I find duplicate records.
    This code is to find duplicate CASE when the case number is entered (first field) a msgbox comes up to indicate that this is a duplicate case number and would I like to view this record Yes or No. If Yes then it opens up that record if No then it opens a new record with the focus on the case number field.
    Now, after investigating the code, I found that in the code I did not capatilize one Case word. I never got a warning so I wasn't sure that it would be a problem, like I said, the code always worked for me but other officers enter data and When I ran a find duplicate query, I found some duplicates.
    So, the code works / dosent work ???

    Private Sub Case_BeforeUpdate(Cancel)As Integer
    Dim strCase As String
    Dim strCriteria As String
    Dim intResponse As Integer

    StrCase = Me.Case.Value
    StrCriteria ="Case = '" & strCase & "'"

    With Me.RecordsetClone
    If Me.RecordsetClone.RecordCount >0 Then
    .FindFirst strCriteria

    If Not.NoMatch The

    IntResponse = MsgBox ("THIS RECORD IS ALREADY ENTERED." & vbNewLine
    & "WOULD YOU LIKE TO VIEW THIS RECORD?", vbYesNo + vbExclamation)
    If intResponse = vbYes Then
    Me.Bookmark = .Bookmark
    Cancel = True
    End If
    End If
    End If
    End With
    End Sub

  2. #2
    Join Date
    Oct 2003
    Try putting the code in the AfterUpdate instead.

  3. #3
    Join Date
    Mar 2009
    Provided Answers: 15
    I agree with christyxo: Processes linked to the BeforeUpdate event often causes subtle problems that are hard to debug.
    Have a nice day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts