Full Version: On Current - If...Then...Enabled
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
C_L
Hello,

I am trying to enable a particular combo box (Department name) when the preceding combo box (Organisation) is a specific entry ("OrganisationA"). If the Organisation is any selection other than "OrganisationA" then I want Department name to be disabled. I am using the On Current function for my form. The following code isn't working:

Private Sub Form_Current()

If Organisation = "OrganisationA" Then
Department_name.Enabled = False
Else
Department_name.Enabled = True
End If

End Sub

Can anyone help?

Many thanks.
missinglinq
If Me.Organisation = "OrganisationA" Then

You also need to place your code in the Organization combobox AfterUpdate event.
Doug Steele
What does "isn't working" mean in this context? Are you getting an error? If so, what's the error? If you're not getting an error, what's happening, and what do you want to have happen instead?

If your complaint is that it's disabling or enabling the Department Name combo box for every row, regardless of what value is in the Organisation combo box for that row, that's the way Access works. While it may look like you have, say, thirty different Department combo boxes, you actually have one combo box repeated thirty times, and changing the combo box affects all instances of it. That shouldn't be a problem, though, since you cannot actually work with the combo box on any other row: attempting to do so will cause the Current event to fire again, so that the combo box you just clicked on will be "correct".
C_L
Hi Doug,

Thanks for helping - I should have been more specific with the "isn't working" comment.

By that I mean nothing happens at all when filling in the form - if an Organisation other than OrganisationA is selected in the Organisation combo box then the Department name combo box is still enabled. I would like the Depatment name combo box to be disabled unless the Organisation is OrganisationA.

Is it possible to do this? (Using this VBA coding I have previously been able to complete a similar task - the only difference being the box I was disabling was a text box and not a combo box.)

Thanks.
Bob_L
QUOTE
Hi Doug,

By that I mean nothing happens at all when filling in the form - if an Organisation other than OrganisationA is selected in the Organisation combo box then the Department name combo box is still enabled. I would like the Depatment name combo box to be disabled unless the Organisation is OrganisationA.

1. The department combo box should then be the second combo filled out.

2. The AFTER UPDATE of the combo box is where the code needs to be (as well as the on current).
C_L
The Department combo box is after the Organisation combo box. I also set the code to the After Update event for the Organisation combo box...still no disabling happening though! Might this be something to do with the fact that the Organisation combo box is a Number data type??
Bob_L
Now that you said that, you would need to use:

CODE
If Me.Organisation.Column(1) = "OrganisationA" Then
    Me.Department_name.Enabled = False
Else
    Me.Department_name.Enabled = True
End If


The bound column for the combo's rowsource is the ID number probably and the description is on field 2 which is column(1) when you use code.
C_L
Excellent, thanks - got it working now! : )
Bob_L
QUOTE
Excellent, thanks - got it working now! : )

Whew! Cool, glad you got it working. sad.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.