Connecting Tech Pros Worldwide Help | Site Map

Search for an existing record

  #1  
Old February 27th, 2007, 07:05 PM
Galka
Guest
 
Posts: n/a
Hello
I have a small database, where names of applicants are recorded with
some other data. If an applicant telephones twice, he can be recorded
twice.

I am trying to check - by name.

When in OnBeforeInsert event of the form, the following code starts
(checked by inserting breakpoint in the code) immediately after
pressing the first key. Naturally it doesn't find anything, because
nothing is entered yet.

When in OnAfterUpdate event, it always finds, - unique name or not. Of
course, the record is already saved.

Where would you recommend to run the following code:

Dim rst As DAO.Recordset, strStudent As String, Resp
Set rst = Forms!frmStudents.RecordsetClone
With rst
strStudent = "[Student Name] = '" & Me![Student Name] & "' AND
SURNAME='" & Me![Surname] & "'"
rst.FindFirst strStudent
If rst.NoMatch Then
Else
Resp = MsgBox("There is a student with the same name. Would you
like to see?", vbYesNo, "CON Faculty waiting lists")
If Resp = vbYes Then
Call FindStudent(Me![Student Name], Me!Surname)
End If
End If
End With
Set rst = Nothing


Thank you.
Galina

  #2  
Old February 27th, 2007, 09:45 PM
Larry Linson
Guest
 
Posts: n/a

re: Search for an existing record


Run it in the BeforeUpdate event of the Controls in which you enter the
field that identifies the applicant -- if it takes two fields, then run it
in the BeforeUpdate for each to determine if both have been entered.

Just a caution: It appears you are using First and Last Name, and that often
is not sufficient because many people can have the same First and Last Name.
And, sometimes people use "nicknames" -- you may have the applicant already
in the DB as "John Smith", when he reapplies as "Jonathan Smith".

Even better, include a ComboBox in the FormHeader with Row Source including
all Records... as the user enters the name, it will scroll, and you can set
it to automatically populate the Form (that's part of the ComboBox Wizard).
Then, if that is not the person, you can have a CommandButton to "Add a New
Applicant".

Larry Linson
Microsoft Access MVP


"Galka" <galkas@mail.ruwrote in message
news:1172602369.443182.3740@j27g2000cwj.googlegrou ps.com...
Quote:
Hello
I have a small database, where names of applicants are recorded with
some other data. If an applicant telephones twice, he can be recorded
twice.
>
I am trying to check - by name.
>
When in OnBeforeInsert event of the form, the following code starts
(checked by inserting breakpoint in the code) immediately after
pressing the first key. Naturally it doesn't find anything, because
nothing is entered yet.
>
When in OnAfterUpdate event, it always finds, - unique name or not. Of
course, the record is already saved.
>
Where would you recommend to run the following code:
>
Dim rst As DAO.Recordset, strStudent As String, Resp
Set rst = Forms!frmStudents.RecordsetClone
With rst
strStudent = "[Student Name] = '" & Me![Student Name] & "' AND
SURNAME='" & Me![Surname] & "'"
rst.FindFirst strStudent
If rst.NoMatch Then
Else
Resp = MsgBox("There is a student with the same name. Would you
like to see?", vbYesNo, "CON Faculty waiting lists")
If Resp = vbYes Then
Call FindStudent(Me![Student Name], Me!Surname)
End If
End If
End With
Set rst = Nothing
>
>
Thank you.
Galina
>

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
add record with some validation tony wong answers 8 October 30th, 2006 07:05 PM
How Do I create a new record from an existing record Tom Cusick answers 1 November 12th, 2005 05:41 PM
With INSERT can I increment an existing value in a column? Randell D. answers 11 July 23rd, 2005 07:50 AM
framework for creating forms, phplib good, are there any options? gonzalo briceno answers 6 July 17th, 2005 12:24 PM