How to enable a control based on a list box selection?

FoxRocks

Registered User.
Local time
Today, 21:43
Joined
Apr 24, 2012
Messages
35
Hello,

I was wondering if there is a way to have a certain field (or control?) become enabled based on what was selected from a list box.
So what I have is a list box with:

- Issued 1
- Issued 2
- Issued 3
- Issued 4

and if the "Issued 1" was selected I would like some controls to become enabled. The controls are:

- Date
- Issued To
- Completed (this is also a list box with yes/no)

Is there a way to do this? I'm still very new to access and especially to VBA coding, so any help would be appreciated :)

Thanks!
~FOX~
 
hi
use select case in after update property
case issued 1
me.date.visible = true
ete
case issued 2
ur condition
case issue 3
ur condition

end select


enjoy
 
Hi Rammundali,

Thank you for the reply!
I've changed the context of my requirements, meaning it's not "issued 1", etc. But the challenge is the same. Here is what I have:

Code:
Select Case Completed1_AfterUpdate()
Case Is = no
Me!NoParts1.Enabled = True
Me!NoTools1.Enabled = True
Me!NoTime1.Enabled = True
Me!IssuedComments1.Enabled = True
Case Else
Me!NoParts1.Enabled = False
Me!NoTools1.Enabled = False
Me!NoTime1.Enabled = False
Me!IssuedComments1.Enabled = False
End Select

It's not working, which I don't expect will come as a surprise to you :)

Thanks a lot for the help!

~FOX~
 
I meant to say that what I do have now is a list box with:

- Yes
- No

and then four controls that I want to be enabled as a result of 'No' being selected. They are:

- NoParts1
- NoTools1
- NoTime1
- IssuedComments1

Thanks again.
 
Hello Fox,
The Select..Case should go inside the After Update property. Your syntax is wrong. it should be something like..
Code:
Private Sub Completed1_AfterUpdate()
Dim Is
Is=Completed1.Value
Case Is = "no"
    Me!NoParts1.Enabled = True
    Me!NoTools1.Enabled = True
    Me!NoTime1.Enabled = True
    Me!IssuedComments1.Enabled = True
Case Else
    Me!NoParts1.Enabled = False
    Me!NoTools1.Enabled = False
    Me!NoTime1.Enabled = False
    Me!IssuedComments1.Enabled = False
End Select
End Sub

You can also use a If/Else/End If structure; if it is going to be only 2 values to check.
 
Last edited:
Hi pr2,

Thanks for the help! I entered the code you kindly provided into my form VBA and I received an error message saying:

"Compile Error:
Expected: Line number or label or statement or end of statement"

I haven't tried to figure it out, I'm going to go do that now, I just thought I would post it right away in case you happened to stop by in the meantime :)

Cheers,
~FOX~
 
Hello FOX hope you have solved the issue.. It just missed the Select case keyword at the start.. I have highlighted it in RED.. Sorry about that..

Code:
Private Sub Completed1_AfterUpdate() 
Dim Is Is=Completed1.Value
[COLOR=Red]Select Case Is[/COLOR]
Case Is = "no"     
     Me!NoParts1.Enabled = True     
     Me!NoTools1.Enabled = True
     Me!NoTime1.Enabled = True
     Me!IssuedComments1.Enabled = True
Case Else
     Me!NoParts1.Enabled = False
     Me!NoTools1.Enabled = False
     Me!NoTime1.Enabled = False
     Me!IssuedComments1.Enabled = False
End Select 
End Sub
 
Hi pr2,

I've edited the code exactly as you have it, however I am receiving an error:

Compile error:
Expected: Identifier

and it highlights this part:

Code:
Private Sub Completed1_AfterUpdate()
Dim [COLOR=Red]Is[/COLOR] Is=Completed1.Value [COLOR=Black]
Select Case Is[/COLOR] Case Is = "no"           
Me!NoParts1.Enabled = True           
Me!NoTools1.Enabled = True      
Me!NoTime1.Enabled = True      
Me!IssuedComments1.Enabled = True 
Case Else      
Me!NoParts1.Enabled = False      
Me!NoTools1.Enabled = False      
Me!NoTime1.Enabled = False      
Me!IssuedComments1.Enabled = False 
End Select  
End Sub
Although I should also mention that this whole part is in red:

Code:
Private Sub Completed1_AfterUpdate()  [COLOR=Red]
Dim Is Is=Completed1.Value[/COLOR] [COLOR=Red]
Select Case Is[/COLOR] 
Case Is = "no"           
Me!NoParts1.Enabled = True           
Me!NoTools1.Enabled = True     
Me!NoTime1.Enabled = True      
Me!IssuedComments1.Enabled = True 
Case Else      
Me!NoParts1.Enabled = False     
 Me!NoTools1.Enabled = False      
Me!NoTime1.Enabled = False      
Me!IssuedComments1.Enabled = False 
End Select  
End Sub
I'm not sure if that's relevant or not.

Thanks for all your help, I really appreciate it :)

~FOX~
 
Last edited:
Hi pr2,

I got something to work without using the Select Case statement. Here is what I have:

Code:
Private Sub Completed1_AfterUpdate()
If Me!Completed1 = "No" Then
Me!NoParts1.Enabled = True
Me!NoTools1.Enabled = True
Me!NoTime1.Enabled = True
Me!IssuedComments1.Enabled = True
Else
Me!NoParts1.Enabled = False
Me!NoTools1.Enabled = False
Me!NoTime1.Enabled = False
Me!IssuedComments1.Enabled = False
End If
End Sub

And so far it works!

Either way, thanks a lot for your time and interest in my problem, I appreciate it :)

~FOX~
 
Is is a reserved word and is unsuitable as a variable name.

Since you only have tow choices in your combo it would be much better to use a Boolean value rather then text. You can still display the text but the bound column should be boolean.

It also allows a much more concise procedure.
The With Block is also useful for tidying up code.

Code:
Private Sub Completed1_AfterUpdate()
 
Dim Enable As Boolean
 
   With Me
      Enable = Not .Completed
 
      .NoParts1.Enabled = Enable
      .NoTools1.Enabled = Enable
      .NoTime1.Enabled = Enable
      .IssuedComments1.Enabled = Enable

   End With
End Sub
 
Hi Galaxiom,

Thanks very much for sharing, that's a really cool way to do that and it cleans up the code nicely too!

~FOX~
 

Users who are viewing this thread

Back
Top Bottom