Heres the code for Load Event()
General_Use_Subs.PopulateComboBox("SELECT * FROM BLACompany", "BLACompany", "BLACompany.CompanyDesc", "BLACompany.CompanyID", cboCompany, sqlConn)
General_Use_Subs.PopulateComboBox("SELECT * FROM BLABusiness WHERE CompanyID = " & cboCompany.SelectedValue, "BLABusiness", "BLABusiness.BusinessName", "BLABusiness.BusinessID", cboBusiness, sqlConn)
General_Use_Subs.PopulateComboBox("SELECT * FROM BLABusinessArea WHERE BusinessID = " & cboBusiness.SelectedValue, "BLABusinessArea", "BLABusinessArea.BusinessAreaName", "BLABusinessArea.BusinessAreaID", cboMainArea, sqlConn)
General_Use_Subs.PopulateComboBox("SELECT * FROM OccupationDiscipline", "OccupationDiscipline", "OccupationDiscipline.OccupationDisciplineName", "OccupationDiscipline.OccupationDisciplineID", cboDiscipline, sqlConn)
General_Use_Subs.PopulateComboBox("SELECT * FROM DepartmentOccupation WHERE OccupationDisciplineID = " & cboDiscipline.SelectedValue, "DepartmentOccupation", "DepartmentOccupation.DepartmentOccupationDesc", "DepartmentOccupation.DepartmentOccupationID", cboOccupation, sqlConn)
General_Use_Subs.PopulateComboBox("SELECT * FROM DepartmentOccupationLevel WHERE DepartmentOccupationID = " & cboOccupation.SelectedValue, "DepartmentOccupationLevel", "DepartmentOccupationLevel.DepartmentOccupationLevelDesc", "DepartmentOccupationLevel.DepartmentOccupationLevelID", cboLevel, sqlConn)
General_Use_Subs.PopulateComboBox("SELECT * FROM CPRDocumentDepartment", "CPRDocumentDepartment", "CPRDocumentDepartment.DocumentDepartmentDesc", "CPRDocumentDepartment.DocumentDepartmentID", cboDocDepartment, sqlConn)
General_Use_Subs.PopulateComboBox("SELECT * FROM CPRDocumentCategory WHERE DocumentDepartmentID = " & cboDocDepartment.SelectedValue, "CPRDocumentCategory", "CPRDocumentCategory.DocumentCategoryDesc", "CPRDocumentCategory.DocumentCategoryID", cboDocCategory, sqlConn)
General_Use_Subs.PopulateComboBox("SELECT * FROM CPRRiskDepartment", "CPRRiskDepartment", "CPRRiskDepartment.RiskDepartmentDesc", "CPRRiskDepartment.RiskDepartmentID", cboRiskDepartment, sqlConn)
General_Use_Subs.PopulateComboBox("SELECT * FROM CPRRiskCategory WHERE RiskDepartmentID = " & cboRiskDepartment.SelectedValue, "CPRRiskCategory", "CPRRiskCategory.RiskCategoryDesc", "CPRRiskCategory.RiskCategoryID", cboRiskCategory, sqlConn)
General_Use_Subs.PopulateComboBox("SELECT * FROM CPRRiskParameter WHERE RiskCategoryID = " & cboRiskCategory.SelectedValue, "CPRRiskParameter", "CPRRiskParameter.RiskParameterDesc", "CPRRiskParameter.RiskParameterID", cboRiskParameter, sqlConn)
General_Use_Subs.PopulateComboBox("SELECT * FROM CPRDocumentProtocol", "CPRDocumentProtocol", "CPRDocumentProtocol.DocumentProtocolDesc", "CPRDocumentProtocol.DocumentProtocolID", cboProtocol, sqlConn)
CheckComboBoxes()
Heres the Populate ComboBox Code:
Public Sub PopulateComboBox(ByVal sqlQueryString As String, ByVal TableName As String, ByVal DisplayMemeber As String, ByVal ValueMember As String, ByVal Field As ComboBox, ByVal Connection As SqlConnection)
Try
Cursor.Current = Cursors.WaitCursor
Field.DataSource = Nothing
Dim sqlDA As New SqlDataAdapter(sqlQueryString, Connection)
Dim sqlDS As New DataSet
sqlDA.Fill(sqlDS, TableName)
Field.DisplayMember = DisplayMemeber
Field.ValueMember = ValueMember
Field.DataSource = sqlDS
Cursor.Current = Cursors.Default
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Information, "ERROR")
End Try
End Sub
Then Heres the check comboBox code:
Private Sub CheckComboBoxes()
If cboBusiness.Items.Count = 0 Then
MsgBox("Please enter a Business at the Setup Page", MsgBoxStyle.Information, "No Business")
Me.Close()
ElseIf cboCompany.Items.Count = 0 Then
MsgBox("Please enter a Company at the Setup Page", MsgBoxStyle.Information, "No Company")
Me.Close()
ElseIf cboDiscipline.Items.Count = 0 Then
MsgBox("Please enter a Discipline at the Setup Page", MsgBoxStyle.Information, "No Discipline")
Me.Close()
ElseIf cboDocCategory.Items.Count = 0 Then
MsgBox("Please enter a Document Category at the Setup Page", MsgBoxStyle.Information, "No Document Category")
Me.Close()
ElseIf cboDocDepartment.Items.Count = 0 Then
MsgBox("Please enter a Document Department at the Setup Page", MsgBoxStyle.Information, "No Document Department")
Me.Close()
ElseIf cboLevel.Items.Count = 0 Then
MsgBox("Please enter an Occupation Level at the Setup Page", MsgBoxStyle.Information, "No Occupation Level")
Me.Close()
ElseIf cboMainArea.Items.Count = 0 Then
MsgBox("Please enter a Main Area at the Setup Page", MsgBoxStyle.Information, "No Main Area")
Me.Close()
ElseIf cboOccupation.Items.Count = 0 Then
MsgBox("Please enter an Occupation at the Setup Page", MsgBoxStyle.Information, "No Occupation")
Me.Close()
ElseIf cboProtocol.Items.Count = 0 Then
MsgBox("Please enter a Protocol at the Setup Page", MsgBoxStyle.Information, "No Protocol")
Me.Close()
End If
End Sub