VBA combobox populated from Form entries

nkasper

New Member
Joined
Jun 28, 2011
Messages
5
I am just getting started in VBA and I have a pretty good start to what I am trying to do. I am basically building a program that will use Excel as the database and report garnering. I have 2 different user forms in the VBA, the first NewWorkOrder and the second WorkOrderDesc. I want to automatically populate the combo box (or list box) in WorkOrderDesc based upon the facility WO Type that was selected in NewWorkOrder. I have the WOType separated on 4 different worksheets, for example, if the user selected "Vehicle" as the WO Type and Facility 10, then I want the combo box (or list box) to populate all instances of facility 10 under the "Vehicle" Worksheet. I have a variable named strFacility and WOType to hold the string values of the selection and NewWorkOrder is hidden so the memory of the strings is still available.

NewWorkOrder form:

Code:
Private Sub CommandButton1_Click()

'Pass values from NewWorkOrder form to frmVehicle and WorkOrderDesc
strFacility = FacListBox.Value
WOType = WOTypeListBox.Value

'Determine if the Work Order Type is Vehicle and needs the Vehicle Form
'No Vehicle Type selection is needed at this time, so I am commenting this portion out. 9/9/11
'If WOType = "Vehicles" Then
'frmVehicle.Show

'If it is not Vehicles, then proceed to Work Order Desc
'Else:

WorkOrderDesc.Show

'End If

Me.Hide

End Sub

Private Sub CommandButton2_Click()

'Ask for confirmation to confirm user wants to close workbook
Select Case MsgBox( _
"Are you sure that you want to close the Work Order System?", _
vbYesNo + vbQuestion, _
"Confirm Exit.")

Case vbYes
'Close Work Order Workbook if user Cancels work order
'Don't save changes since no WO was entered.
ThisWorkbook.Close SaveChanges:=False


Case vbNo
'Don't Close Work Order System, return to previous screen
NewWorkOrder.UndoAction

End Select
End Sub

Private Sub UserForm_Initialize()

'Populate the Facility List based upon the Database
Dim LastRow As Long, facility As Range
With Worksheets("FacilitiesDB")

'Find the Last Row in the Worksheet
LastRow = .Cells(Rows.Count, 1).End(xlUp).Row

For Each facility In .Range("A2:A" & LastRow)
If Len(facility) > 0 Then FacListBox.AddItem facility.Value
Next facility
End With

'Populate the Work Order Type List - hard coded!
With WOTypeListBox
.AddItem "Vehicles"
.AddItem "Building"
.AddItem "Grounds"
.AddItem "Equipment"
.AddItem "Other"
End With

End Sub

Thanks in advance for your help...
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Forum statistics

Threads
1,224,504
Messages
6,179,144
Members
452,891
Latest member
JUSTOUTOFMYREACH

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