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

Disabling fields for one record only/ validation rule with If statement

4
Hello,

Here is my question.

I've got several check boxes on my form (yes/no questions for users). And one check box that says "None of the above".
If the latter is ticked: 1) all other check boxes become disabled, and 2) Access checks if any of them were ticked and if it's true alerts user about the error.

For #1 I wrote a code in After Update event to disable all other boxes, but it disables them for all records. How can I do it only for current record.
For #2 I also wrote a code, but I'm wondering if it can be done using validation rule of the control. Is it possible to write an expression for validation rule to accomplish the task.

Would appreciate any suggestions!
Apr 8 '12 #1
7 2835
Mihail
759 512MB
For #1: No way (as far as I know)

For #2: I don't think so. Again as far as I know, the validation rule can't be a function. Here I am not so sure, sorry.
Apr 8 '12 #2
Rabbit
12,516 Expert Mod 8TB
For 1, use the On Current event. If fires whenever the record changes. Use it to enable/disable appropriately.

For 2, it may be possible. Try it and see. I don't have Access on this computer to confirm.
Apr 8 '12 #3
Sylvio
4
There is no On Current event for check box control, only for the Form in general. In this case for the action to take place I need to either go to next record or push Refresh All. But I would like to have a check box that disables some of the fields while user can continue to work with other fields for this record.
What I'm thinking is - I can use On Current event of my form, and use the check box to run Requery command, but this command takes me back to first record.
Apr 9 '12 #4
Rabbit
12,516 Expert Mod 8TB
You don't need an On Current event for the check box. You need to use the one on the form. Use it to check the value of the checkbox and enable/disable as appropriate.

I'm not sure why you would use the Requery command. That doesn't disable or enable anything.
Apr 9 '12 #5
Sylvio
4
"You need to use the one on the form. Use it to check the value of the checkbox and enable/disable as appropriate."
Yes, I've tried it as you suggested. But It doesn't disable right after I tick the check box, only when I go to the next record or Refresh All.
Apr 9 '12 #6
Mihail
759 512MB
From what I read until now, your goal is not to enable/disable the checkboxes. Your goal is to deny to be checked the checkbox that say "None of the above".
Or, if this one is checked, to deny to be checked any other checkbox for a choice.
And this can be achived with simple code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub ChkChoice_1_BeforeUpdate(Cancel As Integer)
  2.     If ChkChoice_1 Then
  3.         If ChkNoChoice Then
  4.             MsgBox ("Message from chkChoice_1:  chkNoChoice is checked")
  5.             Cancel = True
  6.         End If
  7.     End If
  8. End Sub
  9.  
  10. Private Sub chkChoice_2_BeforeUpdate(Cancel As Integer)
  11.     If ChkChoice_2 Then
  12.         If ChkNoChoice Then
  13.             MsgBox ("Message from chkChoice_2:  ChkNoChoice is checked")
  14.             Cancel = True
  15.         End If
  16.     End If
  17. End Sub
  18.  
  19. Private Sub chkNoChoice_BeforeUpdate(Cancel As Integer)
  20.     If ChkNoChoice Then
  21.         If ChkChoice_1 Or ChkChoice_2 Then
  22.             MsgBox ("Message from chkNoChoice: You already made a choice")
  23.             Cancel = True
  24.         End If
  25.     End If
  26. End Sub

Also you can use another strategy:
Expand|Select|Wrap|Line Numbers
  1. Private Sub chkChoice_1_BeforeUpdate(Cancel As Integer)
  2.     If ChkChoice_1 Then
  3.         ChkNoChoice = False
  4.     End If
  5. End Sub
  6.  
  7. Private Sub ChkChoice_2_BeforeUpdate(Cancel As Integer)
  8.     If ChkChoice_2 Then
  9.         ChkNoChoice = False
  10.     End If
  11. End Sub
  12.  
  13. Private Sub ChkNoChoice_BeforeUpdate(Cancel As Integer)
  14.     If ChkNoChoice Then
  15.         ChkChoice_1 = False
  16.         ChkChoice_2 = False
  17.     End If
  18. End Sub
Apr 9 '12 #7
Rabbit
12,516 Expert Mod 8TB
I didn't say remove your code from your other event. I only said use the On Current event. You use the On Current to solve the issue of changing records. You keep your existing code in the After Update to handle user input.
Apr 9 '12 #8

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

Similar topics

2
by: Dalan | last post by:
This ought to be simple enough, but not certain which to use. I have a few fields set to Require data to be entered; however, the message displayed by Access 97 is too generic to be of any real...
2
by: Joey P | last post by:
Hi all, I am doing a project for university whereby i have to implement a simple database related to a frozen foods company. I am having some trouble though creating a validation rule for one...
0
by: Steve V | last post by:
I'm using Access 2000 to build a budgeting/tracking database. Can I make a validation rule (using VBA) that checks the data as if the record has already been added? I've got 5 tables (only the...
6
by: Chuck | last post by:
A97. A database has a table: tblA which has a single text field, B. It is a primary field, indexed and no duplicates. It is used as a lookup for table tblC. A form based on tblA is used to add...
2
by: Ben.j.howard | last post by:
In my table i would like to create a validation rule for a yes/no field. I would like it, to only allow you to check yes, if two other fields are already ticked as yes. Example; Field 1:...
3
by: BrianB830 | last post by:
Hello all, I have a quick question regarding an MS Access database I'm creating. In the entity "ORDER", I have the attributes "Order Date" and "Delivery Date". I need to create a validation...
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...
6
by: solargovind | last post by:
Hi, How to set Validation Rule? Example, my Textbox should not be empty. So, I set validation rule as "Not null". But it shows only at the end of record save. I must need to show when they...
8
by: preeny8 | last post by:
Hi guys, So I'm editing an existing database (Access 2003), and I need a bit of help in making a validation rule. My table has many fields, 3 of which are indexed (location, number & revision) ...
1
by: MLH | last post by:
Anyone remember if A97 append query failure would ever report data breaking validation rule when such was not the case. I have an old SQL statement - several years old now. I've encountered a case...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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,...

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.