473,472 Members | 2,140 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

MS ACCESS: How to enable control in a form based on another control

22 New Member
I want to know how I can enable (activate) a control in a form if another control is filled. For example, I have a questionnaire and I want to skip questions depending on the answer of a previous question.
Feb 29 '08 #1
5 5700
Stewart Ross
2,545 Recognized Expert Moderator Specialist
I want to know how I can enable (activate) a control in a form if another control is filled. For example, I have a questionnaire and I want to skip questions depending on the answer of a previous question.
In the After Update event of the control that you want filled you can use VBA code to to un-enable controls you do not wish the user to enter, as follows:

Expand|Select|Wrap|Line Numbers
  1.  Dim IsFilled as Boolean
  2. IsFilled = Not IsNull(Me.NameOfControl)
  3. Me.FirstSkippedControl.Enabled = Not IsFilled
  4. Me.FirstSkippedControl.Locked = IsFilled
  5. Me.SecondSkippedControl.Enabled = Not IsFilled
  6. Me.SecondSkippedControl.Locked = IsFilled
  7. ....
It would be best to store this in the form's code module as a separate Sub which could be called from the original control's AfterUpdate event. If you do go this route you also have to call the same routine from the form's On Current event, to ensure that the right pattern of enabled/unenabled controls is shown for each record subsequently scrolled by the user.

-Stewart
Feb 29 '08 #2
EORTIZ
22 New Member
Hi Stewart, thanks a lot for the reply.

I am in the very beginner stage of using programming so I need a little moe help. Let's say that I have an option group control called Q1, and a second option group control called Q2. I need that Q2 be disabled until selected in Q1 the value of 1. Otherwise need to be disabled.

Another thing that I need to do is to be able to clear the option group controlQ1 for the case that it is filled incorrectly and should be left blank. In that case Q2 need to be disabled and its value deleted.
Mar 3 '08 #3
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Hi Stewart, thanks a lot for the reply.

I am in the very beginner stage of using programming so I need a little moe help. Let's say that I have an option group control called Q1, and a second option group control called Q2. I need that Q2 be disabled until selected in Q1 the value of 1. Otherwise need to be disabled.

Another thing that I need to do is to be able to clear the option group controlQ1 for the case that it is filled incorrectly and should be left blank. In that case Q2 need to be disabled and its value deleted.
Hi Eortiz. I'm not clear that you can choose 'incorrect' values in an option group - the range of values is restricted to those you define when you create the options. Anyway, to answer your question, you could use a Select Case construct in the AfterUpdate event of control Q1. I can only offer a guide as to how to construct it:
Expand|Select|Wrap|Line Numbers
  1. Select Case Me.Q1
  2.    Case 1
  3.        Me.Q2.Enabled=True
  4.        Me.Q2.Locked = False
  5.    Case 2
  6.    (add suitable code for other correct values if needed)
  7.    Case 3
  8.    (add suitable code for other correct values if needed)
  9.    Case else
  10.       Q1 = Null
  11.       Q2 = Null
  12.       Q2.Enabled = False
  13.       Q2.Locked = True
  14. End Select
Whilst I have included the enabling of Q2 in the Case statement I reckon this would be better separated out as a separate test. I can't advise further on this as you don't give any details of what other conditions may also be valid for the Q1/Q2 controls.

You will also need to refer to this code in the On Current event of your user form, which means it is best to write it as a separate subroutine that is itself called from the Q1 after update and form on current events.

-Stewart
Mar 3 '08 #4
EORTIZ
22 New Member
Thanks for your response, I appreciate the timeliness of it.


It is possible than the person doing data entry by mistake select an option and there was not a response for a particular question, so need to uncheck the control. If selecting option1 from the control, the second control will be enabled, and if it is changed to option2 in the first control, the second control need to be cleared and disabled.

I had found out how to do it:

In the after update of control 1:
Expand|Select|Wrap|Line Numbers
  1. If.Me.optgroup.value=1 then 
  2.   me.optgroup2.enabled=true
  3. else me.optgroup2.enabled=false
  4.        me.optgroup2=null
  5. end if
to only uncheck an option in the option group control, in the Double Click event:
Expand|Select|Wrap|Line Numbers
  1. Private Sub optgroup_DblClick(Cancel As Integer)
  2. Me.optgroup = Null
  3. End Sub
Mar 3 '08 #5
NeoPa
32,556 Recognized Expert Moderator MVP
All you need if you're simply setting the visibility is :
Expand|Select|Wrap|Line Numbers
  1. Me.optGroup2.Visible = (Me.optGroup = 1)
This automatically sets it visible if Me.optGroup = 1, and sets it invisible if Me.optGroup <> 1.
Mar 7 '08 #6

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

Similar topics

3
by: Jouke Langhout | last post by:
Hello all! For quite some time now, I've got the following problem: Access won't close properly when a user closes the application. An ACCESS process stays active and that process can only be...
3
by: Random Person | last post by:
Does anyone know how to use VBA to relink tables between two MS Access databases? We have two databases, one with VBA code and the other with data tables. The tables are referenced by linked...
0
by: Michael Holberton | last post by:
Hi All, I have Access 97, 2000 & 2002 installed in different directories under Win2K Server on a new PC box I built. The Calendar Control on my Date Selector Form is not working and causing...
5
by: Andrew Chanter | last post by:
Does anyone know a way you can use conditional formatting to create a banded style view as is commonly seen on the internet. (In othe words the first record appears on a gray background, the 2nd...
52
by: Neil | last post by:
We are running an Access 2000 MDB with a SQL 7 back end. Our network guy is upgrading to Windows Server 2003 and wants to upgrade Office and SQL Server at the same time. We're moving to SQL Server...
5
by: Lyle Fairfield | last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/callnetfrcom.asp The Joy of Interoperability Sometimes a revolution in programming forces you to abandon all...
15
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to...
4
by: kev | last post by:
Hi folks, I have created a database to store information on equipments. During the first level of registration, there is a form that i need the user to fill up details on the equipment testing....
2
by: kartikss | last post by:
I Have Created A Table & Form : Named : "Security Control" : Field Having User Id - Text (pk) Password - Text Data Entry Enable - Yes / No Option Report Enable - Yes / No Option And I...
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...
1
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
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...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.