Form fields based on others

rc-alex

Registered User.
Local time
Today, 06:10
Joined
Apr 29, 2011
Messages
106
Hello,

I have a complicated form, in wich fields may be selectable or not, or required or not, based on other forms. Looking for some guidance or tutorial as to how to set this up. Here is part of the form:

[Checkbox A]
[Checkbox B]
[Field A]
[Field B]
[Field C]
[Field D]

Checkbox B cannot be selected unless Checkbox A is selected.
If checkbox A as selected and B is selected nothing else is required.
If checkbox A is selected and Checkbox B is not, then Field A is required.
Depending on the value of Field A, either Field B, C, or D will be required.

Seems complicated... Is there a guide that explains how to get started?

Thanks!
 
Sample Code for your problem is given below:

Code:
Private Sub Form_Current()
If CheckBoxA Then
   CheckBoxB.Enabled = True
   Me![FieldA].Enabled = True
   Me![FieldB].Enabled = False
   Me![FieldC].Enabled = False
   Me![FieldD].Enabled = False
Else
   CheckBoxB.Enabled = False
End If
End Sub

Private Sub CheckBoxB_Click()
If Me!CheckBoxB Then
   Me!FieldA.Enabled = False
   Me![FieldB].Enabled = False
   Me![FieldC].Enabled = False
   Me![FieldD].Enabled = False
End If

End Sub

Private Sub FieldA_LostFocus()
Dim aVal
aVal = Nz(Me![FieldA], 0)
Select Case aVal
    Case 1
        Me![FieldB].Enabled = True
        Me![FieldC].Enabled = False
        Me![FieldD].Enabled = False
    Case 2
        Me![FieldB].Enabled = False
        Me![FieldC].Enabled = True
        Me![FieldD].Enabled = False
    Case 3
        Me![FieldB].Enabled = False
        Me![FieldC].Enabled = False
        Me![FieldD].Enabled = True
End Select
End Sub

Above Code is not tested for accuracy. You may try the code with corrections of Field Names and Events etc. Try out and make required adjustments in the code with corrections.
 
Thanks!
So this would be a VB module?

In place of CheckboxA, I can't just put the name of the checkbox, right? I need to somehow specify that it is selected. Same for the rest, needing to specify the values, etc.

And how do I add that to the form? I created the module in VBA but it doesn't seem to be taking effect?

Thanks!
 
Last edited:

Users who are viewing this thread

Back
Top Bottom