Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IF...Then to Enable and disable controls on a form 1

Status
Not open for further replies.

Pistol

MIS
Jan 29, 2001
59
US
I need help creating an if then statement to disable a control on a subform., and enable others. Here is the logic.

If option 1 on subform 1 (on form 1) is checked (or true), I want to disable option 2,3,4, and 5. If option 2 is checked, (or true) I want to disable option 1,3,4, and 5.

Thanks in advance
 
If I read this right it sounds a bit like a catch 22!!

If Option 1 is selected, and 2,3,4 & 5 are disabled, how will you ever select option 2? It seems like you will only ever want options 1 & 2 anyway?

Georg
 
However... to be a bit more constructive on the matter

Assuming the options are in a option group then use the On Got Focus event on the relevent option button and use the code Me.Option-x.Enabled = True/False to enable/disable any option button e.g.

Private Sub Option1_GotFocus()

Me.Option2.Enabled = False
Me.Option3.Enabled = False
Me.Option4.Enabled = False
Me.Option5.Enabled = False

End Sub

If they are individual checkboxes then just use the On Click or After Update event to fire the same code
 
Option 2 can be selected if option 1 is unchecked. By disabling the other options the user is forced to pick the subcontrols of option 1 (i.e. option 1-A,B,C).

I have a course of action/decision matrix, and I need to limit user choices. If a user checks off "Inoperative Product" (option 1) s/he will need to select "Send Replacement", or "Credit Account" (option 1-A,B), and nothing else. If the user checks off "Customer Ordered Incorrectly" (Option 2) s/he will need to select "Credit Account" (i.e. option 1-B), and nothing else.

With the if then else statement all the controls are enabled unless one of the options are checked off. The sole purpose is to limit the margin of error.
 
That works for the check boxes (What I am calling option1,2,3), but If I uncheck the box then the controls are still disabled (I need them to be enabled). Would this be better with a If...Then Statement?

Private Sub InOpPro_AfterUpdate()
Me.InOpSndReplace.Enabled = True
Me.InOpCrdAcct.Enabled = True
Me.CrdAcctPONum.Enabled = False
Me.CrdAcctInvNum.Enabled = False
End Sub

 
OK, I get u now.. you would be best using the if... then as follows..

Private Sub Check1_AfterUpdate()

If Me.Check1 Then
Me.Check2.Enabled = True
Me.Check3.Enabled = True
Me.Check4.Enabled = True
Me.Check4.Enabled = True
Else
Me.Check2.Enabled = False
Me.Check3.Enabled = False
Me.Check4.Enabled = False
Me.Check4.Enabled = FaLse
End If


End Sub
 
That's exactly what I ended up doing...I haven't touched VB, or VBA in three years....I'm very rusty. Thanks for your help
 
Is there a reason you don't use a group of radio buttons instead of check boxes?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top