473,399 Members | 4,192 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,399 software developers and data experts.

Help with Validation argument

17
Hi
Hope you can help me with this
I run Access2000 on XP

Form has 3 fields:
  • cboSTATUS - which can be set via Limited value List A B or Complete. Default is set as A.
    cboTHIS - which can be set via Limited Value List X, Y or Z. No Default. Intiially field in blank (Null).
    txtTHAT - which can be anything. No Default text. Intiially field in blank (Null).


SCENE1: User goes to work on a record and initially all 3 fields are set as above (A, Null and Null).
The User sets cboStatus as Complete and attempts a Save/Close of the record.
I then run validations to ensure the other 2 fields have valid data for a Completed cboStatus setting.ie:
  • cboTHIS - cannot be Y or Null, but can be X or Z.
    txtTHAT - cannot be blank

If an ivalid entry is detected in THIS or THAT, msg box pops up and SaveClose action cancelled.

I set the validation arguments as:
If IsNull(Me.cboTHIS) Or Me.cboTHIS = "" Or Me.cboTHIS = "Y" And Me.cboStatus = "Completed" Then
MsgBox etc.....

ElseIf IsNull(Me.cboTHAT) Or Me.cboTHIS = "" And Me.cboStatus = "Completed" Then
MsgBox etc.....


I thought this worked a charm. I tested by having both THIS and THAT wrong, or both right, or one wrong, one right. Validation code worked as desired.
I tested by having THIS and THAT either wrong or right, with cboStatus set as A and as as expected, Save was actioned (because no Validation rule was broken since cboStatus was not set as Completed)

SCENE2: However I have found - if User later comes BACK into the record, after it passed the above validations.
Then changes
  • cboStatus to A
    changes cboTHIS to Y
    changes txtTHAT to nothing (Null, "")

and tries to SaveClose, the Validation code runs, and act as if the cboStatus is set as Completed. ie. it says THIS cannot be Y and THAT cannot be Null. I want , in this case to accept the save, because cboStatus is not set as Complete!

I think it's the Or bit in the argument? Because if I take that out, and have just the following, I have no problem with SCENE2. ie The User can save the form as it's been edited:
If IsNull(Me.cboTHIS) And Me.cboStatus = "Completed" Then
MsgBox etc....


Am I missing ( )or [ ] or ! or all, in crucial places?.
Hope this is not too confusing (you should be in my side of the screen :-))

Thanks for all help!
Cheers
AMBLY
Jun 12 '07 #1
4 1427
puppydogbuddy
1,923 Expert 1GB
If you want all the conditions to be true at the same time, try replacing each of the "or's" with "And" and see what happens.
Jun 12 '07 #2
AMBLY
17
Hi puppydogbuddy

Thanks for replying!

But that doesn't make sense to me? how can for eg, cboTHIS be Null AND "Y" at the same time?

1. If IsNull(Me.cboTHIS) Or Me.cboTHIS = "" Or Me.cboTHIS = "Y" And Me.cboStatus = "Completed" Then
2. MsgBox etc.....


But I tried it out anyway - and if I change all the Or's to And essentially what happens is that everything is acceptable to Access - eg: it allows Y and Completed combination, which I don't want.

I still think, it could be because I'm not bracketing right, or perhaps there are too many arguments? ......Because I thought I understood that If IsNull(Me.field1) Or Me.Field1 = "" was good programming, I made each of my Validation arguments have that initial code before then either:
adding a second OR (if there was a 3rd thing field item to be validated) then adding the AND (specifying the text against which the IF and OR's were being checked against.

Anyway, what I have done is remove all the OR "" parts, and where there is a need for two OR's (Null or Y), I have just created 2 seperate ElseIFarguments, one after the other - and now it seems to work OK in all scenarios (so far anyway!)

cheers
AMBLY
Jun 13 '07 #3
puppydogbuddy
1,923 Expert 1GB
Hi puppydogbuddy

Thanks for replying!

But that doesn't make sense to me? how can for eg, cboTHIS be Null AND "Y" at the same time?

1. If IsNull(Me.cboTHIS) Or Me.cboTHIS = "" Or Me.cboTHIS = "Y" And Me.cboStatus = "Completed" Then
2. MsgBox etc.....


But I tried it out anyway - and if I change all the Or's to And essentially what happens is that everything is acceptable to Access - eg: it allows Y and Completed combination, which I don't want.

I still think, it could be because I'm not bracketing right, or perhaps there are too many arguments? ......Because I thought I understood that If IsNull(Me.field1) Or Me.Field1 = "" was good programming, I made each of my Validation arguments have that initial code before then either:
adding a second OR (if there was a 3rd thing field item to be validated) then adding the AND (specifying the text against which the IF and OR's were being checked against.

Anyway, what I have done is remove all the OR "" parts, and where there is a need for two OR's (Null or Y), I have just created 2 seperate ElseIFarguments, one after the other - and now it seems to work OK in all scenarios (so far anyway!)

cheers
AMBLY
Ambly,
Glad you got it resolved, but just in case you need it, I am passing along this tip:

If(nz(Me!field1, "")) = "" does the same as your statement below without the "Or". It uses the "null to zero string function"..

If IsNull(Me.field1) Or Me.Field1 = ""
Jun 13 '07 #4
AMBLY
17
Thanks Puppydogbuddy!

I will certainly store that one in my growing file of Access Tricks!
I might just have a go doing that instead of my (possibly not good) surgery on the code...

This forum is a great help for newbies like me, glad I found it.

Cheers
AMBLY
Jun 13 '07 #5

Sign in to post your reply or Sign up for a free account.

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...
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...
5
by: Chris | last post by:
Based upon some prevoius postings on what to do for adding a 'add' row to a datagrid I utilize the footer to create the 'add' row. The only issue is that I have it sharing the 'UpDate_Command' and...
1
by: Kum | last post by:
Hi, I need help in asp.net dynamic textbox controls validation. I am creating textbox controls dynamically on a asp.net webpage. Now after creating the textboxes on the page I want to validate...
0
by: dhurwitz | last post by:
Hi, In my ASP.NET 2.0 web app, I have a user control, ucBinEdges, with several text boxes. The user control has several validation controls validating the Text of these text boxes -...
11
by: Rik | last post by:
Hello guys, now that I'm that I'm working on my first major 'open' forms (with uncontrolled users I mean, not a secure backend-interface), I'd like to add a lot of possibilities to check wether...
3
by: teo | last post by:
Mozilla error on postback and validation ----------- A Button causes a Listbox to desappear. If no item has been selected on the Listbox, all is OK. If one or more items are selected,
3
by: matko | last post by:
This is a long one, so I'll summarize: 1. What are your opinions on raising an exception within the constructor of a (custom) exception? 2. How do -you- validate arguments in your own...
53
by: souporpower | last post by:
Hello All I am trying to activate a link using Jquery. Here is my code; <html> <head> <script type="text/javascript" src="../../resources/js/ jquery-1.2.6.js"</script> <script...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
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,...
0
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...
0
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...
0
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...
0
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,...
0
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...

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.