VBA Drop Down Box Activation

peterengland

New Member
Joined
Apr 6, 2005
Messages
7
I wanted a way of blanking out different fields on my customer form depending on weather it is a Business, Private or Caravan customer. The solution I got was to create 3 command buttons and using On Click and then entering the following in the code builder:


Private Sub Command14_Click()
Me.Business1.Enabled = False
Me.Business2.Enabled = False
End Sub

Private Sub Command15_Click()
Me.Caravan1.Enabled = False
Me.Caravan2.Enabled = False
End Sub

Private Sub Command23_Click()
Me.Private1.Enabled = False
Me.Private2.Enabled = False
End Sub


This allowed me to click the command button and for example the business1 and business2 fields greyed out. Also on the form I have a combo box with the following:

Business
Private
Caravan

Instead of click on the command button to activate the VB Code is it possible to click on for example business in the combo box and it load the business VB code.

Sorry for this being so long hope it makes sense and I would greatly appreciate any help/input
Kind Regards
Peter
:-D :-D
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
You need to use one of the events associated with the combobox.

Perhaps After Update.
Code:
Private Sub Combo0_AfterUpdate()
    Caravan1.Enabled = Combo0 = "Caravan"
    Caravan2.Enabled = Combo0 = "Caravan"
    Business1.Enabled = Combo0 = "Business"
    Business2.Enabled = Combo0 = "Business"
    Private1.Enabled = Combo0 = "Private"
    Private2.Enabled = Combo0 = "Private"

End Sub
By the way why do you have seperate fields for business, private and caravan?
 
Upvote 0
Thank You

Cheers Norie it did exacly what I wanted it to do. By the way I do have some seperate fields for business, private and caravan that is why I wanted to know this. Cheers Again
Peter
 
Upvote 0
Peter

Is the data in the seperate fields for Business etc similar data?

If it is then you could just use fields for what that information is and add another to indicate which type of data is it.
 
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,119
Members
452,381
Latest member
Nova88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top