Action based on Combo Box Selection

G

Guest

I have a TranType combo box with 2 columns. Column 1 is the TranID, and
column 2 is the TranName. If a user selects "Revenue" in the combo box
(which is TranID 1), then it enables the Rate and Members controls. This
code isn't working. Can anyone debug?


Private Sub TranType_AfterUpdate()

If Me!TranType.Column(1) = 1 Then
Me.Rate.Enabled = True
Me.Members.Enabled = True
End If

End Sub
 
M

Marshall Barton

Kirk said:
I have a TranType combo box with 2 columns. Column 1 is the TranID, and
column 2 is the TranName. If a user selects "Revenue" in the combo box
(which is TranID 1), then it enables the Rate and Members controls. This
code isn't working. Can anyone debug?


Private Sub TranType_AfterUpdate()

If Me!TranType.Column(1) = 1 Then
Me.Rate.Enabled = True
Me.Members.Enabled = True
End If

End Sub


The Column index is zero based.

Your code is incomplete in that it should probably disable
the controls when a different trantype is selected.

Try this:
Me.Rate.Enabled = (Me!TranType.Column(0) = 1)
Me.Members.Enabled = (Me!TranType.Column(0) = 1)

Note that if the combo box's BoundColumn property is set to
1, the combo box's Value will be the trantype value
(regardless of the column displayed in it text portion.
This means that you don't need to use the Column(0) property
at all:
Me.Rate.Enabled = (Me!TranType) = 1)
Me.Members.Enabled = (Me!TranType = 1)
 
G

Guest

Thanks!

Marshall Barton said:
The Column index is zero based.

Your code is incomplete in that it should probably disable
the controls when a different trantype is selected.

Try this:
Me.Rate.Enabled = (Me!TranType.Column(0) = 1)
Me.Members.Enabled = (Me!TranType.Column(0) = 1)

Note that if the combo box's BoundColumn property is set to
1, the combo box's Value will be the trantype value
(regardless of the column displayed in it text portion.
This means that you don't need to use the Column(0) property
at all:
Me.Rate.Enabled = (Me!TranType) = 1)
Me.Members.Enabled = (Me!TranType = 1)
 

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