Gray out combo box base on value list (1 Viewer)

ivonsurf123

Registered User.
Local time
Today, 01:49
Joined
Dec 8, 2017
Messages
69
Hello,

I just can't figure out how to grey out the combobox when value chosen is "closed". combobox is set to have a value list in the resource type and the resource is "Open", "Closed"

Code:
If Me.[Position_Status] = "Closed" Then
    Me.[Position_Status].Enabled = False
  Else
    Me.[Position_Status].Enabled = True
End If
 

isladogs

MVP / VIP
Local time
Today, 09:49
Joined
Jan 14, 2017
Messages
18,219
The code will work provided the 'Closed' value is the bound field (normally hidden)in your combobox (Position_Status)
If that is a value in the 2nd visible column, then do one of the following:
a) change the code to reference the corresponding value in the hidden bound (ID?) field
b) change the first line to:
Code:
If Me.[Position_Status].Column(1) = "Closed" Then
 

ivonsurf123

Registered User.
Local time
Today, 01:49
Joined
Dec 8, 2017
Messages
69
Thank you Ridders, but did not work...The one I submitted does it, but it does not stay gray out, it just flash it and go back to showing the field with value enable again when I change to another record

Code:
If Me.[Position_Status].Column(1) = "Closed" Then
    Me.[Position_Status].Enabled = False
  Else
    Me.[Position_Status].Enabled = True
End If
 

Beetle

Duly Registered Boozer
Local time
Today, 02:49
Joined
Apr 30, 2011
Messages
1,808
Is this a continuous (aka multiple items) form? if so this is not going to behave like you're expecting. A continuous form is really just one set of Controls that is repeated for each row of data in the record source. Any code like this that you use to manipulate the behavior of a given Control based on the current row is going to be applied to the instance of that Control for all rows. You might be able to use Conditional Formatting, in which case you might need two rules;

Expression Is [Position Status] = "Open" (leave the Enabled property on)
Expression Is [Position Status] = "Closed" (turn the Enabled property off)
 

missinglinq

AWF VIP
Local time
Today, 04:49
Joined
Jun 20, 2003
Messages
6,423
Which event is your code used in?

This is really important! Are you getting an error message? If you're trying to Disable the Combobox using one of its events, such as its AfterUpdate event, it won't work, because you cannot Disable a Control while it has Focus.

You wouldn't really want to Disable it while making your original selection from it...what would happen if the user made a mistake, or changed their mind...they couldn't correct it.

For the Enable/Disable property to be Record-appropriate, your code would need to be in the Form_Current event.

Linq ;0)>
 

ivonsurf123

Registered User.
Local time
Today, 01:49
Joined
Dec 8, 2017
Messages
69
No I am not receiving an error message, I am using it in the current event. but is not behaving well, It is a continuous form. Thank you for helping.
 

missinglinq

AWF VIP
Local time
Today, 04:49
Joined
Jun 20, 2003
Messages
6,423
With a Continuous View Form (or a Datasheet View Form) you have to use Conditional Formatting, as Beetle suggested:

In Form Design View:
  1. Right-Click on the Combobox
  2. Click on Conditional Formatting
  3. Under 'Condition1' select Expression Is
  4. In the next box, enter [Position Status] = "Closed"
  5. Now click on the 'Enabled' icon...the one on the far right (to turn the Enabled property off)
  6. Now click on OK
Now you're done!

Linq ;0)>
 

Users who are viewing this thread

Top Bottom