Solved

Activate command button only when combo box has value

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

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…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
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 …
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

776 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