browse: forums | FAQ
Connecting Tech Pros Worldwide

Hey there! Do you need Microsoft Access / VBA help?

Get answers from our community of Microsoft Access / VBA experts on BYTES! It's free.

many controls

Site Addict
 
Join Date: Feb 2007
Posts: 553
#1: Jul 27 '07
Hi,

If there are so many controls on a form - check boxes, radio buttons, texboxes, etc.

How can i know if any of these are changed - thier value changed, etc

If any of these is changed ... then do something.

Thanks



Member
 
Join Date: Jul 2007
Posts: 66
#2: Jul 27 '07

re: many controls


Right click on the item and add some code. Something like build... I think (in dutch is "gebeurtenis opbouwen")
Site Addict
 
Join Date: Feb 2007
Posts: 553
#3: Jul 27 '07

re: many controls


Twanne

I said i have items not just a single item.

There are 10s of controls , how can you set onChange event or something with everyone ?

Ofcouse a better method is needed

Quote:

Originally Posted by Twanne

Right click on the item and add some code. Something like build... I think (in dutch is "gebeurtenis opbouwen")

missinglinq's Avatar
Moderator
 
Join Date: Nov 2006
Location: Richmond, Virginia USA
Posts: 3,144
#4: Jul 27 '07

re: many controls


Is there one thing you want to do if any of the controls change, or are there different things you want to do, depending on which controls change?

Linq
Site Addict
 
Join Date: Feb 2007
Posts: 553
#5: Jul 27 '07

re: many controls


I want to do one thing if any of the controls change

Quote:

Originally Posted by missinglinq

Is there one thing you want to do if any of the controls change, or are there different things you want to do, depending on which controls change?

Linq

missinglinq's Avatar
Moderator
 
Join Date: Nov 2006
Location: Richmond, Virginia USA
Posts: 3,144
#6: Jul 27 '07

re: many controls


This will immediately run the code with the input of a single character into any field
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Dirty(Cancel As Integer)
  2.  'Code to run goes here
  3. End Sub
  4.  
This will run the code when the record is saved if a single character has been entered into any field
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.  'Code to run goes here
  3. End Sub
  4.  
If you only want the code to run when a record is being edited, not when a new record is being entered, use this code
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.  If Not Me.NewRecord Then
  3.   'Code to run goes here
  4.  End If
  5. End Sub
  6.  
  7. Private Sub Form_Dirty(Cancel As Integer)
  8.  If Not Me.NewRecord Then
  9.   'Code to run goes here
  10.  End If
  11. End Sub
Linq
Site Addict
 
Join Date: Feb 2007
Posts: 553
#7: Jul 31 '07

re: many controls


HI Linq

The code you have give works fine. What if i want to check other things like change of check-box value or radio button value?

If their value change then do something ......Again i have so many of these on the form.

Thanks

Quote:

Originally Posted by missinglinq

This will immediately run the code with the input of a single character into any field

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Dirty(Cancel As Integer)
  2.  'Code to run goes here
  3. End Sub
  4.  
This will run the code when the record is saved if a single character has been entered into any field
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.  'Code to run goes here
  3. End Sub
  4.  
If you only want the code to run when a record is being edited, not when a new record is being entered, use this code
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.  If Not Me.NewRecord Then
  3.   'Code to run goes here
  4.  End If
  5. End Sub
  6.  
  7. Private Sub Form_Dirty(Cancel As Integer)
  8.  If Not Me.NewRecord Then
  9.   'Code to run goes here
  10.  End If
  11. End Sub
Linq

missinglinq's Avatar
Moderator
 
Join Date: Nov 2006
Location: Richmond, Virginia USA
Posts: 3,144
#8: Jul 31 '07

re: many controls


The code you've got will work for any change in your record, including checkboxes and radio buttons. If you want to perform something when the value of a particular control (checkbox, radio button or whatever) you have to put the code in the BeforeUpdate sub for the particular control.
Reply