473,320 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

User Input Validation - Data Checking

I am using a routine to check to see if a phone number (PK) has alread
been entered, and takes the user to that record if it is found -- as
follows:

Private Sub Contact_telephone___BeforeUpdate(Cancel As Integer)
Dim rs As DAO.Recordset
Dim iAns As Integer
Set rs = Me.RecordsetClone
rs.FindFirst "[phone] = '" & Me![Contact Telephone #] & "'"
If Not rs.NoMatch Then
iAns = MsgBox("Phone " & Me![Contact Telephone #] & " already
exists;" _
& vbCrLf & "Click OK to go to that record, Cancel to start over",
_
vbOKCancel)
Cancel = True
If iAns = vbOK Then
Me.Undo
Me.Bookmark = rs.Bookmark
Else
Me.Undo
End If
Else
' New Customer -- Just let it be added
End If

End Sub

-- This works as designed when you enter a number that is already in
the database.

The problem is when the customer calls and opens a record with a
different telephone number. What I am trying to do to deal with this
possibility is use the same code (above) for the first name and the
last name -- to at least alert the user that there is a possibility
that the name may already be entered.

The code I am using is similar to the above as follows:

Private Sub LName_BeforeUpdate(Cancel As Integer)
Dim rs As DAO.Recordset
Dim iAns As Integer
Set rs = Me.RecordsetClone
rs.FindFirst "[FName]&[LName] = '" & Me![FName] & Me![LName] & "'"
If Not rs.NoMatch Then
iAns = MsgBox("Last Name " & Me![LName] & " already exists;" _
& vbCrLf & "Click OK to go to that record, Cancel to Continue", _
vbOKCancel)
Cancel = True
If iAns = vbOK Then
Me.Undo
Me.Bookmark = rs.Bookmark
Else
' <<<<<<<<<<<<<<<<<<<< Where problem is
>>>>>>>>>>>>>>>>>>>

End If
Else
' New Customer -- Just let it be added
End If

End Sub

So -- From the top, what happens:
1. Customer, John Smith with telephone 123-456-7890 -- it is entered.
2. Same customer, John Smith calls again with telephone 234-123-4567.
3. Above routine finds John Smith and indicates that the name may be
in the database. User has option to go to that record (OK), or
(Cancel to Continue), Here is the problem: As it is, when you select
Cancel, it stays in the Lastname field and when you try to advance to
the next field, it triggers the BeforeUpdate event again, etc. What
is the best way to set the environment up so that it is the way it was
before the BeforeUpdate event was triggered -- so that the user can
continue to input the record.

Thanks for any help with this.

Robbie Bollinger

What happens is when the first name and the last name is entered.
Nov 12 '05 #1
2 2813
R Bolling wrote:
So -- From the top, what happens:
1. Customer, John Smith with telephone 123-456-7890 -- it is entered.
2. Same customer, John Smith calls again with telephone 234-123-4567.
3. Above routine finds John Smith and indicates that the name may be
in the database. User has option to go to that record (OK), or
(Cancel to Continue), Here is the problem: As it is, when you select
Cancel, it stays in the Lastname field and when you try to advance to
the next field, it triggers the BeforeUpdate event again, etc. What
is the best way to set the environment up so that it is the way it was
before the BeforeUpdate event was triggered -- so that the user can
continue to input the record.

Thanks for any help with this.

Robbie Bollinger


I can't imagine using a phone number as a primary key. If I were
designing your tables, I'd have an autonumber field and a phone number.
But you may have a reason for that.

Are you sure that the first name ALWAYS exists?

You could put your routine in the AfterUpdate event instead and do a
Me.Undo

Here is what I have done in the past when I want to stay in the same field
but clear out the entry so I can move on to the next field if I use the
BeforeUpdate event of the control.
Sub Field_BeforeUpdate(Cancel as integer)
If validationcheckfails then
Cancel = True
Me.Field.Undo
Sendkeys "{Del}"
endif

but you want to move to the record when the validation fails. You could
set a form global variable to true or false at the top of your code
Option Explicit
Option Compare
Dim blnGoOn As Boolean

In your BeforeUpdate, instead of setting Cancel = True, set blnGoTo
If I need to go to other record then
blnGoTo = True
Else
blnGoTo = False
Endif

And in the AfterUpdate event do something like
If blnGoTo then
Me.Undo
...code to go to other record
endif

But you can avoid a lot of this by simply checking in the AfterUpdate
event.


Nov 12 '05 #2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Here's an If...Then construct I use to do the same thing in the
control's BeforeUpdate event procedure. It checks for SSN in the db.
The function "SSN_exists()" returns True/False when the user entered
SSN is already in the db. If the user clicks the "Yes" button on the
MsgBox the routine "RetrievePatient()" changes the form's RecordSource
to retrieve the record w/ the user-entered SSN. The importance of
this If...Then construct is the order in which "things are done..."

1. Is there another record with the data the user just entered?
2. Ask if user wants to get that record.
3. If Yes then Undo the form and set up the form to show the existing
record.
4. If there exists a record w/ just entered data & user doesn't want
to retrieve that record, Cancel the Controls Update.

"Things done" steps are in parentheses.

If SSN_exists(strSSN) Then ' (1)
intAnswer = MsgBox(MSG, vbQuestion + vbYesNo, myCaption)
If intAnswer = vbYes Then ' (2)
Me.Undo ' (3)
Call RetrievePatient(strSSN) ' (3)
End If
Cancel = True ' (4)
End If

End Sub

HTH,

MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBP/d8QIechKqOuFEgEQLHgACglrQ8K3407p8mH4SLkJ0lVR0+12MA niGO
6QOM/C67OLCMoG2AP7kG2BPm
=lJVg
-----END PGP SIGNATURE-----
R Bolling wrote:

< SNIP >
The code I am using is similar to the above as follows:

Private Sub LName_BeforeUpdate(Cancel As Integer)
Dim rs As DAO.Recordset
Dim iAns As Integer
Set rs = Me.RecordsetClone
rs.FindFirst "[FName]&[LName] = '" & Me![FName] & Me![LName] & "'"
If Not rs.NoMatch Then
iAns = MsgBox("Last Name " & Me![LName] & " already exists;" _
& vbCrLf & "Click OK to go to that record, Cancel to Continue", _
vbOKCancel)
Cancel = True
If iAns = vbOK Then
Me.Undo
Me.Bookmark = rs.Bookmark
Else
' <<<<<<<<<<<<<<<<<<<< Where problem is

End If
Else
' New Customer -- Just let it be added
End If

End Sub

Robbie Bollinger


Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Jay | last post by:
Hi everybody! Please help me with this problem. I try to write code for server side data validation. Initially, I have a html file called "form.html" which just contains all the necessary fields...
1
by: Tonta | last post by:
Hi I wanted to know how i could validate a users input. I.e to ensure that all data that is entered into a textbox is an interger, text, etc? can anyone point me to some useful articles im...
4
by: santa19992000 | last post by:
can I use scanf to get input (some times user enters input sometimes not, just hit keyboard)?. It displays to enter IP address, if user wants to change, then he enters, otherwise he hits keyboard,...
3
by: A TO Consultant | last post by:
Hi All, I am working on a web application that uses both asp classic and asp.net pages. We need to validate user input to avoid attacks like sql injection. Can a component be created that both...
4
by: joesin | last post by:
I recently found a vulnerability on my website that allowed sql injection. I have been trying to write some code that would clean user data but have been running into problems. The validation still...
8
by: Phil Latio | last post by:
I've been creating an application over the last few weeks and generally pleased with what I have produced but one area is irritating me, form validation. At the moment the forms are simply...
95
by: hstagni | last post by:
Where can I find a library to created text-based windows applications? Im looking for a library that can make windows and buttons inside console.. Many old apps were make like this, i guess ...
30
by: Yorian | last post by:
Hey, Although I've been using classes and object for quite a while now I've never actually programmed proper OO code yet. It ofcourse depends on what you call proper OO code. I have been...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.