
Testing for a record already in existence
Nick,
You could set a multiple field index on the table, and set it to be unique.
The problem with this is that it IS possible that you get 2 Nick Allens
working for you, and the db would not allow this unless you included another
field to differentiate them.
You could use the persons phone number as a unique index, but again, if you
get hubby and wife with the same number, you run into trouble.
You could also use a Domain function such as DCount to check for the
existence of a similar name. You can then allow duplicates, but flag the
user upon entry of a duplicate. Maybe bring up a modal form with a 'like'
criteria and let them select or add.
I have a similar situation where the user types into, or selects, the name
from a combo box, and I use the Not in List event to open another form to
either select an existing user or add a new one.
Another possibility is to have all the staff in a subform, with a text box
on the main form to type what you are looking for.
The On Change event of the text box has code to find a close record in the
subform. eg;
Private Sub txtFindWhat_Change()
If Me.txtFindWhat.Text = "" Then Exit Sub
Application.Echo False
Me.ofsMembers.SetFocus
Me![ofsMembers].Form![LastName].SetFocus
DoCmd.FindRecord Me.txtFindWhat, acStart, , acDown, , acCurrent, True
Me.txtFindWhat.SetFocus 'Set it back for the next char...
Me.txtFindWhat.SelStart = 255 '...to the end
Application.Echo True
End Sub
This can be slow with a big list.
Hope this is of some use to you.
Jeff Davies
Quote:
> Anyone able to point me in the right direction?
> I have a fairly simple relational staff database set up which handles
First
> Name, Last Name, Telephone, Dept, Title, Photo etc etc.
> As 3 people have access to the database for inputting new users, what I'd
> like to do is to have an Event that OnUpdate for the last name field
checks
> to see if there's already someone called that name. At the moment we're
> getting a few duplicate entries and it would help if it would pop up a
> message saying "A person/People of this name already exist(s) - would you
> like to cancel this new record?" or something similar.
> What will I need to do to create a Boolean function which returns True if
> the person exists and False if not. Sorry if this sound Basic I'm just not
> that familiar with recordsets etc.
> I know it's pretty much
> Function StaffExists(First, Last As String) As Boolean
> found = false
> do loop until found=true or eof
> goto next record and compare the first and last names with the
> parameters
> loop
> StaffExists = found
> End Function
> But what do i need to do in between the Function and End Function to build
a
> recordset!
> Sorry for my utter naivety.
> Nick.