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

Checkboxes and BeforeUpdate Event

15
I’m trying to work out some VBA code to test the condition/value of a couple of checkboxes. I want this code to run in the BeforeUpdate event. I found something similar, just not similar enough.

https://stackoverflow.com/questions/3813760/determine-whether-a-access-checkbox-is-checked-or-not

Here’s what I’m playing with. I have four checkboxes.

chkCheckBox1
chkCheckBox2
chkCheckBox3
chkSomethingIsChecked

The Tag property for the first three checkboxes has been set to “ABC”

Here is the original code I was trying:

Expand|Select|Wrap|Line Numbers
  1. Dim ctrl As Control
  2. For Each ctrl In Me.Controls
  3.     If ctrl.Tag = "ABC" Then
  4.         If ctrl.Value = True Then
  5.             chkSomethingIsChecked.Value = True
  6.         Else
  7.             chkSomethingIsChecked.Value = False
  8.         End If
  9.     End If
  10. Next ctrl
I realize this won’t work because it would seem that whatever the condition of the first two checkboxes it is only the condition of the last checkbox that determines if chkSomethingIsChecked is true or false.

Next, I tried:
Expand|Select|Wrap|Line Numbers
  1. Dim ctrl  As Control
  2. Dim CheckBoxCount as Integer
  3.  
  4.     For Each ctrl In Me.Controls
  5.         If ctrl.Tag = "ABC" Then
  6.             If ctrl.Value = True Then CheckboxCount = CheckboxCount + 1
  7.         End If
  8.     Next ctrl
  9.  
  10.     If CheckboxCount > 0 Then
  11.         chkSomethingIsChecked.Value = True
  12.     Else
  13.         chkSomethingIsChecked.Value = False
  14.     End If
This didn’t work, either. So, I put the code in a Command Button and tried it. It worked perfectly.

That leads me to ask is there something about the BeforeUpdate event that is different than a Click event and causes this code to fail?
May 1 '16 #1

✓ answered by jforbes

What you are experiencing makes perfect sense. From MSDN, BeforeUpdate:
The BeforeUpdate event occurs before changed data in a control or record is updated.
So as you are iterating through the controls and inspecting their values, they haven't changed yet. They are in the process of changing and you have the option to cancel their changes. Typically, the BeforeUpdate event's best use is for validation of the Value.

Your code should work if you move it to the AfterUpdate Event.

1 2247
jforbes
1,107 Expert 1GB
What you are experiencing makes perfect sense. From MSDN, BeforeUpdate:
The BeforeUpdate event occurs before changed data in a control or record is updated.
So as you are iterating through the controls and inspecting their values, they haven't changed yet. They are in the process of changing and you have the option to cancel their changes. Typically, the BeforeUpdate event's best use is for validation of the Value.

Your code should work if you move it to the AfterUpdate Event.
May 2 '16 #2

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

Similar topics

8
by: DylanM | last post by:
I have some checkboxes that are generated from the results of a database search. At the moment, the checkboxes are part of a table making up a form. Users are going through the form, clicking the...
7
by: todholt | last post by:
Hello, I am trying to bypass a form's automatic update, and instead call a stored procedure in sql server. I am using continuous forms. The problem I am having is with returning to the next...
0
by: Deano | last post by:
My beforeupdate event on the main form fires when a change has been made and the record has not been saved (2 variables are used to track this). Works great but if they make a change in my...
10
by: MLH | last post by:
Would like to examine the value entered into a textbox on an A97 form during the BeforeUpdate event. The textbox may or may not have had an earlier entry in it prior to the latest value that is...
6
by: lorirobn | last post by:
Hi, I have a form with a continuous subform. I am working on putting validations in for the subform's required fields. Being somewhat new to Access (or rather, an antiquated mainframe...
0
by: adolph | last post by:
Hi, I have a beforeupdate evbent that tests to see that a customer chosen before the user can enter an amount. If the customer has not been chosen yet, then I would like to popup a message...
8
by: evn678 | last post by:
Hello all, I am trying to handle a scenario where a user clicks the 'X' close control on a form window border. I want to force the user to use the form's 'save' button to write the updated...
16
Seth Schrock
by: Seth Schrock | last post by:
I have some code in the forms BeforeUpdate event that checks if a certain checkbox is checked. If it is not, I have a message appear that says "Do you wish to cancel this transaction?" with VbYesNo...
13
Seth Schrock
by: Seth Schrock | last post by:
I am getting an error when trying to cancel my form's BeforeUpdate event. It says: You can't save this record at this time. ACH Manager may have encountered an error while trying to save a...
8
by: elturbo3 | last post by:
I have a form with a BeforeUpdate event that populates other text fields when the user makes a selection in a combobox. I want the user to be able to enter new text into the combobox and tab 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...
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:
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
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
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

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.