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:
Thanks in advance for your help...
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...