Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old February 27th, 2007, 07:05 PM
Galka
Guest
 
Posts: n/a
Default Search for an existing record

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
Default 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
>

 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles