Results 1 to 3 of 3
  1. #1
    4 Star Lounger
    Join Date
    May 2002
    Location
    Roanoke, Virginia, USA
    Posts
    493
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Duplicate Records (A2K SR1)

    I have a frmCustomerEntry which has the following Before Update Event Procedure in the forms
    Properties to check to see whether or not the customer is already in the database:

    Private Sub Form_BeforeUpdate(Cancel As Integer)
    'The BeforeUpdate event allows you to test to see
    'if a record exists before inserting it a second time.
    If Me.NewRecord = True Then
    Dim strWhere As String, strMessage As String
    strWhere = "LastName = '" & Me!LastName & "'"
    Me.RecordsetClone.MoveFirst
    Me.RecordsetClone.FindFirst strWhere
    Do Until Me.RecordsetClone.NoMatch
    If Me.RecordsetClone!FirstName = Me!FirstName Then
    strMessage = "This guest is already in the database. "
    strMessage = strMessage & " Please verify the information being entered."
    strMessage = strMessage & " Click OK and the original record will be displayed."
    MsgBox strMessage, vbInformation, "Matching Record"
    Cancel = True
    DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo
    Me.Bookmark = Me.RecordsetClone.Bookmark
    Exit Sub
    End If
    Me.RecordsetClone.FindNext strWhere
    Loop
    End If
    End Sub

    The procedure works fine until the last name has an apostrophe in it, e.g. O

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Duplicate Records (A2K SR1)

    Is there any chance that the last name will ever contain a double quote? If not, you can use

    strWhere = "LastName = " & Chr(34) & Me!LastName & Chr(34)

    Chr(34) is a double quote.

  3. #3
    4 Star Lounger
    Join Date
    May 2002
    Location
    Roanoke, Virginia, USA
    Posts
    493
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Duplicate Records (A2K SR1)

    I think a double quote in the last name would be remote. This solves the immediate problem.
    Many Thanks.

    Tom

Posting Permissions

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