Command Button visible dependant on a value

O

ollygregory

I know this has been mentioned before a couple of threads back, but the
person asking that question seemed to have mucho better knowledge on
the subject than me!

I have a combo box, that has three options in it, simply, "A", "V" and
"P" I also have a command button, linked to a macro that opens a form.
The data required on the form is only relevant, and therefore only
needs to entered for "A" and "P"... therefore I only want the combo box
to be visible when either of these values are displayed. When "V" is
displayed, I do not want the combo box to be visible.

I have had a go using VB and stuff and have so far had no luck
what-so-ever. I'm sure for someone a little more experienced than
myself this will probably be sufficiently easier but I am totally
stumped on it atm!!

PLEASE HELP!!

Cheers, O
 
G

Graham Mandeno

Hi Olly

Let's say your command button is named "cmdOpenForm" and your combo box is
named "cboOption".

If you change the value of the combo, you might need to change the
visibility of the command button, so make an AfterUpdate event procedure for
the combo. You will After Update in the properties sheet for the combo box.
Type a left square bracket [, and then click the build button with three
dots. You will see this in the code window:

Private Sub cboOption_AfterUpdate()
|
End Sub

At the cursor, type the following line of code:

cmdOpenForm.Visible = (cboOption = "A") Or (cboOption = "P")

If your combo box is bound to a field in your RecordSource, then you will
also want to check when you change records whether or not to display the
command button. So, add an event procedure for the form's Current event and
insert the same line of code into that procedure.
 
A

Al Camp

Olly,
Use the AfterUpdate event of your combo...
Private Sub cboYourCombo_AfterUpdate()
If cboYourCombo = "A" or cboCYourCombo = "P" Then
cmdYourButtonName.Enabled = True
Else
cmdYourButtonName.Enabled = False
End If
End Sub

(I've used Enabled, but you can substitute Visible if you want.)

If cboYourCombo is bound to a field in your table, then you'll need the same
code on the OnCurrent event of the form.
 
O

ollygregory

Woo hoo!!

We got there in the end! :) Had a bit of trouble, but I think it was
because my VB code in other parts of that particular form was a little
bit untidy, but I redid the form and copied back in the buttons,
entered the code, and it now works peeerrrrfectyl!!

Thanks to both of you for all your help!

Olly
 
E

emilio

ollygregory said:
Woo hoo!!

We got there in the end! :) Had a bit of trouble, but I think it was
because my VB code in other parts of that particular form was a little
bit untidy, but I redid the form and copied back in the buttons,
entered the code, and it now works peeerrrrfectyl!!

Thanks to both of you for all your help!

Olly
 
Top