473,626 Members | 3,965 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_telepho ne___BeforeUpda te(Cancel As Integer)
Dim rs As DAO.Recordset
Dim iAns As Integer
Set rs = Me.RecordsetClo ne
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_BeforeUpd ate(Cancel As Integer)
Dim rs As DAO.Recordset
Dim iAns As Integer
Set rs = Me.RecordsetClo ne
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 2827
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_BeforeUpd ate(Cancel as integer)
If validationcheck fails 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 "RetrievePatien t()" 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(strS SN) 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:::mgf0 0 <at> earthlink <decimal-point> net
Oakland, CA (USA)

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

iQA/AwUBP/d8QIechKqOuFEgE QLHgACglrQ8K340 7p8mH4SLkJ0lVR0 +12MAniGO
6QOM/C67OLCMoG2AP7kG 2BPm
=lJVg
-----END PGP SIGNATURE-----
R Bolling wrote:

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

Private Sub LName_BeforeUpd ate(Cancel As Integer)
Dim rs As DAO.Recordset
Dim iAns As Integer
Set rs = Me.RecordsetClo ne
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
2602
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 for user to submit their contact info (name, phone, email, address.....etc...). All user's input will be sent to "processForm.php" using POST. In processForm.php, I want to be able to re-display the form in "form.html" with valid user's input and...
1
1442
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 using vb.net to create a windows applicataion.
4
3869
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, which should prompt next one, how can I do in C program?. Thanks. enter IP address:
3
2322
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 page types can use? Is that the best approach? Would I simply use pattern matching to validate strings and/or remove any unwanted characters? Thanks in advance.
4
2313
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 works, however so does the injection methods I have used.... These are the examples of code I have tried to use to fix the problem. 1. FrmUserName=replace (FrmUserName, " ' ", "") 2. function stripQuotes(FrmUserName) stripQuotes =...
8
2770
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 static html templates and the form input is checked using a validation class. Basically each form field is checked, every error is stored to an array and at the end of checking of the complete form, the array is output neatly at the top of the form. ...
95
5037
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 ____________________________________ | | | ------------------ | | | BUTTON | | | ...
30
3151
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 seperating parts of the website. Like a user class, guestbook class, etc. But I've been putting all the code in one single class instead of of spreiding it. Since a short while I've been reading up on OOP and now I am trying to actually do things the...
0
8266
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8705
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8638
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8365
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8505
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7196
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5574
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4198
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1811
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.