Solved

Activate command button only when combo box has value

Posted on 2003-12-07
4
291 Views
Last Modified: 2012-06-27
I have a form with several command buttons on it.  I also have a combo box which contains various dates.  Some of the command buttons are only relevant if/when a particular date has been selected in the combo box.

I would like for those date-dependant command buttons to only be "active" when a date has been selected in the combo box.  If the combo box is blank (meaning no date has been selected, then I want those buttons to be "inactive".  I would like to have the buttons remain on the form in all cases, but perhaps be "dimmed out" or transparent when they are not to be pressed.

Anyone know what I'm talking about that could help me figure out how to get this done?  The less code the better, as I am a newbie in every sense of the word! :)

Thanks,
-howard.
0
Comment
Question by:hhammack
  • 2
  • 2
4 Comments
 
LVL 11

Expert Comment

by:BillPowell
Comment Utility
Heres a simple way.

Change the buttons enabled property to No.
Then in the afterupdate event for the combo box test for a value.

Private Sub MyCombo_AfterUpdate()
If Me!MyCombo <> "" Then
Me!MyButton.Enabled = True
End If
End Sub

You can use this for any of your buttons.

Hope this helps,

Bill
0
 

Author Comment

by:hhammack
Comment Utility
Bill,

That works great, except that if the user selects a value in the cbo and then later decides to delete that value, then the button remains active.  How do I add parameters to make the button disable again if the user deletes the value?

0
 
LVL 11

Accepted Solution

by:
BillPowell earned 250 total points
Comment Utility
Good Point.  Those users are kind of sneaky.  Try this.

Add this as its own procedure:

Private Sub CheckCombo
  If Me!MyCombo <> "" Then
    Me!MyButton.Enabled = True
  Else
    Me!MyButton.Enabled = False
  End If
End Sub

Then call it from a couple of events:

Private Sub MyCombo_AfterUpdate()
Call CheckCombo
End Sub

Private Sub MyCombo_GotFocus()
Call CheckCombo
End Sub

You can use this in any event for the combo that you want.  Putting it in the onchange cant hurt either.

Bill
0
 

Author Comment

by:hhammack
Comment Utility
Excellent!  Thanks!
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now