Enable / Disable cbo based on another cbo

A

Andy Roberts

I have two combos the first shows companies and the second filters to show
employees based on the selection from the first combo.

I want the second combo to be disabled until a selection is made in the
first combo and I have it disabled using the on_load event for the form and
the following code in the after update event of the first combo

Private Sub cboClientID_AfterUpdate()
If Me.cboClientID = Null Then
Me.cboClientRepID.Enabled = False
Else
Me.cboClientRepID.Enabled = True
End If

Me.cboClientRepID.Requery

End Sub

The problem is that if I delete everything in the first combo (i.e. make it
blank then I would have thought the "else" section would have disabled the
second combo again but it dosesn't. How can I tweak the above code to
disable the 2nd combo if I clear the value in the first?

--
Regards

Andy
___________
Andy Roberts
Win XP Pro
Access 2007
Liverpool, UK
 
L

Linq Adams via AccessMonster.com

" I would have thought the "else" section would have disabled the second
combo"

How is the "Else" going to disable cboClientRepID when it reads

Me.cboClientRepID.Enabled = True

setting Enabled to True?

Actually, the code is correct, given the scenario you presented. The problem
is your syntax is incorrect for Access VBA. The line

If Me.cboClientID = Null Then

should be

If IsNull(Me.cboClientID) Then

Also, in order for the Enabling/Disabling to persist (i.e. to be set properly
as you move from one record to another) you'll need to place the same code in
the Form_Current event.
 
A

Andy Roberts

Linq

Thanks for the correct syntax. If I understand you correctly the code
should now read...

Private Sub Form_Current()
If IsNull(me.cboClientID) Then
Me.cboClientRepID.Enabled = False
Else
Me.cboClientRepID.Enabled = True
End If

Me.cboClientRepID.Requery

End Sub

This doesn't produce any erro but does leave the cboClientRepID control
disabled. I see what you are saying regarding the else line, in isolation
but (im sure im wrong) the above code says to me if the cboClientID is blank
then disable the cboClientRepID otherwise enable it if contains something.

Is this not right?

--
Regards

Andy
___________
Andy Roberts
Win XP Pro
Access 2007
Liverpool, UK
 
L

Linq Adams via AccessMonster.com

The code

If IsNull(me.cboClientID) Then
Me.cboClientRepID.Enabled = False
Else
Me.cboClientRepID.Enabled = True
End If

needs to be in the

Form_Current event

***and***

in the

cboClientID_AfterUpdate event!

if the cboClientID is blank then disable the cboClientRepID otherwise enable it >if contains something.
Is this not right?

Yes, that's correct, but that's the opposite of what you originally said.
 
A

Andy Roberts

Thanks

Works a treat

--
Regards

Andy
___________
Andy Roberts
Win XP Pro
Access 2007
Liverpool, UK
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top