Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check if both names added to form

Status
Not open for further replies.

TrekBiker

Technical User
Nov 26, 2010
334
GB
I'm using AfterUpdate on the Last Name field on a form to check for duplicated names and Undo if necessary, like this

Code:
Private Sub LastName_AfterUpdate()

Dim NewCustomer As String
    Dim stLinkCriteria As String

    NewCustomer = Me.FullName.Value
    stLinkCriteria = "[FullName] = " & "'" & NewCustomer & "'"
       
    If DCount("FullName", "qryClients", stLinkCriteria) > 0 Then
        DoCmd.OpenForm "frmCheckName", acFormDS
    
    End If

'Check for possible duplicate
    If Me.FullName = DLookup("[FullName]", "qryClients", stLinkCriteria) Then
        If MsgBox("This person, " & NewCustomer & ", is already in the database." _
        & vbCr & vbCr & "Do you want to add another customer with this name?", vbYesNo) = vbNo Then
            Me.Undo
            DoCmd.Close acForm, "frmCheckName"
        Else
            DoCmd.Close acForm, "frmCheckName"
            Exit Sub
        End If
    End If
    
End Sub

How can I do the check if the user only enters a First Name?
 
It looks to me like you have those 3 fields on your Form:
FirstName
LastName
FullName
and you have a field FullName in your qryClients query.

Somewhere before LastName_AfterUpdate you join FirstName & LastName to get the FullName to check against FullName in your query.

2 questions:
1. If you just have First Name, do you have a filed in your query to check it against?
2. Why do you want to do that? If users types "Bob", why do you want to check if you already have "Bob" in your query?

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 

I want to prevent the user entering a second record for Bob if there's already a Bob with the same address. frmCheckName will show First Name, Last Name and Address so the user can check, and undo if this will be a duplicate.

My problem is that the AfterUpdate on Last Name won't fire if this field isn't completed.
 
I want to prevent the user entering a second record for Bob if there's already a Bob with the same address

Check both the first name after update and the address after update
If the first name is not null and the address is not null then check to see if there is a record with that first name and that address.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top