Solved

Activate command button only when combo box has value

Posted on 2003-12-07
4
303 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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

932 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