Solved

Activate command button only when combo box has value

Posted on 2003-12-07
4
325 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
ID: 9894110
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
ID: 9894130
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
ID: 9894167
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
ID: 9894198
Excellent!  Thanks!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

735 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