PDA

View Full Version : Check entered text



Cass
01-26-2006, 04:21 AM
Hi!
Is it possible to check two fields new entries when inserting.

Like inserting Personal Names (2 different fields) and if name (first name + last name ) exist then inform user. :think:

input way is table and form depends which is possible to check the name

XLGibbs
01-26-2006, 06:59 AM
Is it possible to set the names as an additional field with the existing primary key? If the names are part of the primary key, the table will generate an error if they already exist. This is the best way to go, if the table is to not have duplicate names.

Otherwise, you can use recordset.Find and search for the last name (then compare the first, if = then whatever you need to do, else whatever happens when they are <>)

geekgirlau
01-26-2006, 05:36 PM
Usually when you are dealing with the names of people, it's highly likely that you are going to get valid duplicate values, so changing the primary key is not an option.

An alternative approach is to display a list of all existing records that contain the same name so the user can check for duplicates, but still add the record if required even if the same name already exists.

XLGibbs
01-26-2006, 05:52 PM
Good alternative. I did mention that the names wouldn't be enough as there would have to be another existing primary key...but on more thought, the same issue of duplicate names would result.

Cass
01-27-2006, 12:01 AM
Seems to be not so easy :( or my english is so bad and don't understand the explanations
i go in this way to decide valid duplicate value people names.
but if i have product and measure then i can't us this because there may many same products and different measure and both repeated

Justinlabenne
01-28-2006, 12:35 AM
Code behind a button on a form you would need to change the field and table names to be valid of course......

On Error Resume Next
Dim f As String
f = DLookup("[pFirstName]", "tblNames", _
"[pFirstName] = """ & Me.pFirstName & """")


Dim l As String
l = DLookup("[pLastName]", "tblNames", _
"[pLastName] = """ & Me.pLastName & """")


If Me.pFirstName & Me.pLastName = f & l Then _
If MsgBox("The name you entered already exists in the database" & vbNewLine & _
"Would you still like to add the name???", 36, "") = 7 Then Exit Sub

DoCmd.GoToRecord , , acNewRec


Check the attached example for implementation: