473,383 Members | 1,834 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,383 software developers and data experts.

Validation Rules and Code

I apparently need a bit of assistance regarding the structure of some
validation code on the BeforeUpdate or AfterUpdate event on a form for
several fields that need to controlled. I did search the archives, but
found nothing precise enough to address my specific needs.

1. There are three text box fields on the form and one of the three
need to have a text value provided. I simply need to ensure that one
field has data, not two, not three and that a choice has to be made so
any of the three cannot be null before leaving record.

2. The other validation is similar. There is a check box on the form
and if checked by a user, then two other fields (one date, one
currency) on the same form required data to be entered before leaving
the record.

Thanks for anyone's assistance. Dalan
Nov 12 '05 #1
3 15886
Dalan,
I made some assumptions about your controlnames:
You have to adjust this of course.
(Air code! Not tested)

Copy the functions FrmValidationx() in your forms module and use this code in the BeforeUpdate event
of your form

If not FrmValidation1() or not FrmValidation2() then
Msgbox "Input is not correct, bla bla"
cancel=true
end if
Function FrmValidation1() as integer
Dim intFilled as integer
If not IsNull(Me!txtFld1) Then intFilled=intFilled +1
If not IsNull(Me!txtFld2) Then intFilled=intFilled +1
If not IsNull(Me!txtFld3) Then intFilled=intFilled +1
If IntFilled =1 Then FrmValidation1 =true
end function

Function FrmValidation2() as integer
If Me!chkBox then
If not IsNull(DateField) AND not IsNull(CurField) Then
FrmValidation2 =true
end if
end if
end function

--
Hope this helps
Arno R
"Dalan" <ot***@safe-mail.net> schreef in bericht
news:50**************************@posting.google.c om...
I apparently need a bit of assistance regarding the structure of some
validation code on the BeforeUpdate or AfterUpdate event on a form for
several fields that need to controlled. I did search the archives, but
found nothing precise enough to address my specific needs.

1. There are three text box fields on the form and one of the three
need to have a text value provided. I simply need to ensure that one
field has data, not two, not three and that a choice has to be made so
any of the three cannot be null before leaving record.

2. The other validation is similar. There is a check box on the form
and if checked by a user, then two other fields (one date, one
currency) on the same form required data to be entered before leaving
the record.

Thanks for anyone's assistance. Dalan


Nov 12 '05 #2
1. Open your table in design view.

2. Click the Properties box View menu).

3. Set the Validation Rule in the Properties box to:
(Abs([Text1] Is Not Null)+Abs([Text2] Is Not Null)+Abs([Text3] Is Not
Null))=1

4. Repace "Text1", "Text2", and "Text3" with the name of your 3 fields.
Notes:
Make sure this goes into the Validation Rule for the table (in the
properties box), not that of a field (in the lower pane of table design).

It works like this:
If Text1 has a value, the phrase:
[Text1] Is Not Null
returns True. To Access, that's -1.
The Abs() function converts that to a number without the negative.
If it's not the case (i.e. if the field IS null), the value is zero.
Summing the 3 values gives you a count of the fields that have a value.
The rule is only satisfied if the count is exactly 1 (not 0 or 2 or 3).

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"Dalan" <ot***@safe-mail.net> wrote in message
news:50**************************@posting.google.c om...
I apparently need a bit of assistance regarding the structure of some
validation code on the BeforeUpdate or AfterUpdate event on a form for
several fields that need to controlled. I did search the archives, but
found nothing precise enough to address my specific needs.

1. There are three text box fields on the form and one of the three
need to have a text value provided. I simply need to ensure that one
field has data, not two, not three and that a choice has to be made so
any of the three cannot be null before leaving record.

2. The other validation is similar. There is a check box on the form
and if checked by a user, then two other fields (one date, one
currency) on the same form required data to be entered before leaving
the record.

Thanks for anyone's assistance. Dalan

Nov 12 '05 #3
Something like
Private Sub Form_BeforeUpdate(Cancel As Integer)

If Not IsNull(Field1) And IsNull(Field2) And IsNull(Field3) Then
Exit Sub
End If

If IsNull(Field1) And Not IsNull(Field2) And IsNull(Field3) Then
Exit Sub
End If

If IsNull(Field1) And IsNull(Field2) And Not IsNull(Field3) Then
Exit Sub
End If

MsgBox "1 field only", vbCritical
Cancel = True

End Sub
Phil

"Dalan" <ot***@safe-mail.net> wrote in message
news:50**************************@posting.google.c om...
I apparently need a bit of assistance regarding the structure of some
validation code on the BeforeUpdate or AfterUpdate event on a form for
several fields that need to controlled. I did search the archives, but
found nothing precise enough to address my specific needs.

1. There are three text box fields on the form and one of the three
need to have a text value provided. I simply need to ensure that one
field has data, not two, not three and that a choice has to be made so
any of the three cannot be null before leaving record.

2. The other validation is similar. There is a check box on the form
and if checked by a user, then two other fields (one date, one
currency) on the same form required data to be entered before leaving
the record.

Thanks for anyone's assistance. Dalan

Nov 12 '05 #4

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

Similar topics

21
by: Stefan Richter | last post by:
Hi, after coding for days on stupid form validations - Like: strings (min / max length), numbers(min / max value), money(min / max value), postcodes(min / max value), telefon numbers, email...
1
by: Mike | last post by:
Note: My XML experience to date has (unfortunately) been limited to reading and thinking, rather than implementation. Anyway, I am in the process of trying to figure out the most efficient way...
4
by: Mike | last post by:
Related to another topic I just posted, I wanted to discuss ways to optimize the validation of very large (>100MB) XML documents. First, I have no idea if something like this already exists; it...
2
by: wumingshi | last post by:
Hi, When validating an XML instance, sometimes the schema is not enough to expression the validation rules. Additional validation rules may be expressed in an application-specific way. For...
67
by: Scott Meyers | last post by:
I have a web site that, due to maintenance by several people, some of whom are fairly clueless about HTML and CSS, etc. (notably me), has gotten to the point where I'm pretty sure it's suffering...
41
by: Gérard Talbot | last post by:
Cross-posted to: comp.infosystems.www.authoring.html and alt.html Followup-to: comp.infosystems.www.authoring.html 1- One day, I stumbled across a website that offers to validate webpages. What...
3
by: Bob Alston | last post by:
I have a routine to copy data to new versions of my app via insert into sql statements. Unfortunately, due to evolution of my app, sometimes the new version has more restrictive editing than an...
10
by: gweasel | last post by:
What is the best way to apply a Validation Rule - or rather, where is the best place to put it? Is there an advantage to putting it on the field in the table vs setting the validation rule on the...
7
ak1dnar
by: ak1dnar | last post by:
Hi, I got this scripts from this URL There is Error when i submit the form. Line: 54 Error: 'document.getElementbyID(....)' is null or not an object What is this error. Complete Files
3
by: Harlequin | last post by:
I must start this posing by making the point that I am NOT a VB programmer and I'm something of a Newbie to MS Access. I can program in a number of languages (Java, Javascript, PERL,PHP and TCL) but...
1
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: 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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.