473,569 Members | 2,573 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Query in VB to Validate data

I'm trying to validate data entered into a form field by using a
Query. I've discovered that the validation rule is pretty useless if
you need anything other than very basic validation.

I've tried using the following After Update Code:

Dim strSQL

strSQL = "SELECT tblProducts.Pro ductSRP FROM tblProducts"
strSQL = & "Where (((tblProducts. ProductID)=[Forms]![frmPeople]![Cases].[Form]![ProductID]));

if strSQL > Me.Compensation AmountTextBox.V alue Then

MsgBox "The amount you entered is invalid"

Me.Compensation AmountTextBox.S etFocus
The idea is that this code validates the data entered and if invalid,
displays the msg box and sends the focus back to the field that
requires a valid entry.

I've also tried to get this to work by creating a Query and
referencing the Query from a Macro or with the expression builder,
with no success.
Can anyone suggest a way to do this?

Thanks,

Fred
Nov 12 '05 #1
4 3482
Let's try the BeforeUpdate event (of the control, not the form) instead and
we'll have to use a query function instead of the query.

LookupValue = DLookup("[ProductSRP]", "tblProduct s", "[ProductID]=" &
Me!Cases.Form!P roductID
If LookupValue > Me.Compensation AmountTextBox.V alue Then
MsgBox "The amount you entered is invalid", vbOkOnly + vbInformation,
"Data Error"
Cancel = True
Me.Compensation AmountTextBox.U ndo
End If
--
Wayne Morgan
Microsoft Access MVP
"fred" <fr**@besttechs olution.com> wrote in message
news:cc******** *************** ***@posting.goo gle.com...
I'm trying to validate data entered into a form field by using a
Query. I've discovered that the validation rule is pretty useless if
you need anything other than very basic validation.

I've tried using the following After Update Code:

Dim strSQL

strSQL = "SELECT tblProducts.Pro ductSRP FROM tblProducts"
strSQL = & "Where (((tblProducts. ProductID)=[Forms]![frmPeople]![Cases].[Form]![ProductID]));
if strSQL > Me.Compensation AmountTextBox.V alue Then

MsgBox "The amount you entered is invalid"

Me.Compensation AmountTextBox.S etFocus
The idea is that this code validates the data entered and if invalid,
displays the msg box and sends the focus back to the field that
requires a valid entry.

I've also tried to get this to work by creating a Query and
referencing the Query from a Macro or with the expression builder,
with no success.
Can anyone suggest a way to do this?

Thanks,

Fred

Nov 12 '05 #2
"fred" <fr**@besttechs olution.com> wrote in message
news:cc******** *************** ***@posting.goo gle.com...
I'm trying to validate data entered into a form field by using a
Query. I've discovered that the validation rule is pretty useless if
you need anything other than very basic validation.

I've tried using the following After Update Code:

Dim strSQL

strSQL = "SELECT tblProducts.Pro ductSRP FROM tblProducts"
strSQL = & "Where (((tblProducts. ProductID)=[Forms]![frmPeople]![Cases].[Form]![ProductID]));
if strSQL > Me.Compensation AmountTextBox.V alue Then


Whoa... you're testing if a STRING is greater-than the value of a TextBox?

In the above, strSQL is equal to the SQL string "SELECT..." not the result of
executing that SQL. You need to use a Recordset based on that SQL or just use a
DLookup() function. Either of those will return the value of ProductSRP from
the table. Then you can compare that to the TextBox value.

You should also be doing this in BeforeUpdate, not AfterUpdate. As the name
suggest the AfterUpdate is too late. BeforeUpdate can be cancelled to prevent
the invalid entry from ever being committed.

Actually, if you used a DLookup() there is no reason a simple Validation Rule
shouldn't work here. The rule would be something like...

<DLookup("Produ ctSRP", "tblProduct s", "ProductID = " & ProductID & "")

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Nov 12 '05 #3
fr**@besttechso lution.com (fred) wrote in
news:cc******** *************** ***@posting.goo gle.com:
I'm trying to validate data entered into a form field by using a
Query. I've discovered that the validation rule is pretty useless if
you need anything other than very basic validation.

I've tried using the following After Update Code:

Dim strSQL

strSQL = "SELECT tblProducts.Pro ductSRP FROM tblProducts"
strSQL = & "Where (((tblProducts. ProductID)=[Forms]![frmPeople]![Cases]. [Form]![ProductID]));
if strSQL > Me.Compensation AmountTextBox.V alue Then

MsgBox "The amount you entered is invalid"

Me.Compensation AmountTextBox.S etFocus
The idea is that this code validates the data entered and if invalid,
displays the msg box and sends the focus back to the field that
requires a valid entry.

I've also tried to get this to work by creating a Query and
referencing the Query from a Macro or with the expression builder,
with no success.
Can anyone suggest a way to do this?

Thanks,

Fred


You might consider how the > operator works on strings.

You might consider what:
strSQL = & "Where (((tblProducts. ProductID)=[Forms]![frmPeople]![Cases].
[Form]![ProductID]));
does to the value stored perviously at strSQL

and you might tell us what you are trying to do, as it's not so clear.

--
Lyle
(for e-mail refer to http://ffdba.com/contacts.htm)
Nov 12 '05 #4
Thanks for the quick suggestions!

I was able to add this to a validation rule. For some reason I could
not get the syntax correct using a before update event in VB.

Thanks much for the help!

"Rick Brandt" <ri*********@ho tmail.com> wrote in message news:<bs******* *****@ID-98015.news.uni-berlin.de>...
"fred" <fr**@besttechs olution.com> wrote in message
news:cc******** *************** ***@posting.goo gle.com...
I'm trying to validate data entered into a form field by using a
Query. I've discovered that the validation rule is pretty useless if
you need anything other than very basic validation.

I've tried using the following After Update Code:

Dim strSQL

strSQL = "SELECT tblProducts.Pro ductSRP FROM tblProducts"
strSQL = & "Where

(((tblProducts. ProductID)=[Forms]![frmPeople]![Cases].[Form]![ProductID]));

if strSQL > Me.Compensation AmountTextBox.V alue Then


Whoa... you're testing if a STRING is greater-than the value of a TextBox?

In the above, strSQL is equal to the SQL string "SELECT..." not the result of
executing that SQL. You need to use a Recordset based on that SQL or just use a
DLookup() function. Either of those will return the value of ProductSRP from
the table. Then you can compare that to the TextBox value.

You should also be doing this in BeforeUpdate, not AfterUpdate. As the name
suggest the AfterUpdate is too late. BeforeUpdate can be cancelled to prevent
the invalid entry from ever being committed.

Actually, if you used a DLookup() there is no reason a simple Validation Rule
shouldn't work here. The rule would be something like...

<DLookup("Produ ctSRP", "tblProduct s", "ProductID = " & ProductID & "")

Nov 12 '05 #5

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

Similar topics

4
5772
by: Russell | last post by:
I'm having a fit with a query for a range of dates. The dates are being returned from a view. The table/field that they are being selected from stores them as varchar and that same field also stores other fields from our dynamic forms. The field is called 'FormItemAnswer' and stores text, integer, date, float, etc. Anything the user can...
1
1540
by: Divya Alice George | last post by:
Dear Sir, My problem is that i am required to validate a given schema against the standard DTDs provided by w3.org- namely xmlschema.dtd and datatypes.dtd. Presently, I load the given schema into an ActiveXObject and use the function validate(). The function validate() does some sort of validation of the given schema aginst the standard...
3
1984
by: PiGei | last post by:
Hi all, I'm trying to build a function that - providing the dbname and the query name - show the results. I don't know how to solve this problem... when I try to insert the variable into this call cnnSimple.x_qry rstSimple
2
10046
by: dc | last post by:
i have a xml file like this: <?xml version="1.0" encoding="utf-8"?> <validate xmlns="http://tempuri.org/fieldValidate.xsd"> <field name="Short Name" type="SN" length="10"> <requiredChar value="Y" errMsg="required Y" /> <requiredChar value="X" errMsg="required X" /> <bannedChar value="Z" errMsg="banned Z" /> <bannedChar value="A"...
3
2254
by: george.lengel | last post by:
Hello experts, I have been struggling for days to solve this problem and every suggestion I find via Google does not work for me. There is probably a solution out there that will do what I want, but I probably have not properly implemented the solutions I find. I am trying to make a page to allow personnel the ability to search our...
4
1912
by: UKuser | last post by:
Hi Guys, I am trying to create an editable table of a MySQL query where every field can be updated. My example script is at: http://nana46.coconia.net/test4.php however I am currently getting Parse errors. Am I missing anything obvious in my code below? Thanks
6
481
by: MVM | last post by:
Hi, I am attempting to run a query in MS SQL server between two tables that have a one to many relationship. The tables are linked on GID. What I want is one instance of every record from Table 1 even if there isn't a record in Table 2; and even if there are multiple records in Table 2. Table 1: GID Parcel
6
2093
by: Drum2001 | last post by:
I have a database where I need to query multiple items. Is it possible to run a query based on a textbox where the information is delimited by a comma. Example: Show me all names where Social Security Number: = 111223333, 444556666, 777889999
1
1452
by: luthriaajay | last post by:
I am stuck with a tricky situation. 1)I am reading element values from an XML document mentioned below: InputDocument.xml ----------------- <?xml version="1.0" encoding="UTF-8"?> <FIXML xmlns="http://www.fixprotocol.org/FIXML-4-4">
0
7701
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...
0
7615
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8130
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...
1
7677
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...
0
7979
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...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
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...
0
3643
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1223
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.