Private Sub DataGrid3_Click()
On Error Goto DBErrorHandler
Dim strSQL As String
Dim ssql2 As String
'Check to see if we are going to display either the department or an individual employee
If indiv = False Then
'Department was selected
ssql2 = "SELECT DepartName FROM tblDepartInfo WHERE DepartNum =" & DataGrid3.Text
Set goGetdepNme = New ADODB.Connection
Set recGetDepNme = New ADODB.Recordset
goGetdepNme.CursorLocation = adUseClient
goGetdepNme.Open "Provider = Microsoft.Jet.OLEDB.4.0;Persist Security Info = False;Data Source = F:\mydb.mdb"
recGetDepNme.Open ssql2, goGetdepNme, adOpenStatic, adLockOptimistic
txtDepartName.Text = recGetDepNme!departname & ""
strSQL = "SELECT EmpNum, EmployeeNme From tblEmployee WHERE DepartNum = " & DataGrid3.Text & " AND ActiveInactive=0"
txtDepartNum.Text = DataGrid3.Text
Adodc2.Enabled = True
Adodc2.RecordSource = strSQL
Adodc2.Refresh
Set DataGrid2.DataSource = Adodc2
ElseIf indiv = True Then
'Individual Employee Was Selected
ssql2 = "SELECT * FROM tblEmployee WHERE EmpNum =" & DataGrid3.Text 'Grabs the Employees Number from the Selected DataGrid3 Text
Set goGetdepNme = New ADODB.Connection
Set recGetDepNme = New ADODB.Recordset
goGetdepNme.CursorLocation = adUseClient
goGetdepNme.Open "Provider = Microsoft.Jet.OLEDB.4.0;Persist Security Info = False;Data Source = F:\mydb.mdb"
recGetDepNme.Open ssql2, goGetdepNme, adOpenStatic, adLockOptimistic
txtDepartName.Text = recGetDepNme!departname & ""
txtDepartNum.Text = recGetDepNme!departnum & ""
txtEmployeeNme.Text = recGetDepNme!EmployeeNme & ""
txtEmpNum.Text = recGetDepNme!empnum & ""
strSQL = "SELECT EmpNum, EmployeeNme From tblEmployee WHERE DepartNum = " & DataGrid3.Text & " AND ActiveInactive=0"
Adodc2.Enabled = False
End If
DBErrorHandler:
MsgBox err.description, err.number
resume next
exit sub
End Sub
Controls On The Form Are As Follows:
optDepartment 'Option Button For Selecting A Department
optEmployee 'Option Button For Selecting A Single Employee
Datagrid3 'Datagrid Control - Displays either Employee Number & Employee Name OR Department Number & Department Name
Datagrid2 'Datagrid Control - Displays only Employee Number & Employee Name IF a Department was Selected, other wise it's disabled if selecting a
'single employee
Datagrid1 'Datagrid Control - Displays the schedule for either the department or employee
Problem Description:
The code display above does not trap any errors, when a user selects the department name or employee name it gives a run time error and exits
the application. The user is supposed to select the DepartNum field if selecting a department or EmpNum field if selecting a individual
employee. If the user does not select a DepartNum or EmpNum, the ssql2 errors out and gives the following error message:
Run Time Error '-2147217904'(8004e10)':
No Value Given For One Or More Required Parameters
I know what this error is and what's causing, I just can't figure out how to tell the user that "Hey you selected a Department Name and not the
Department Number, try again" Or "Hey you selected an Employee Name and not the Employee Number, try again!"
On Error Goto DBErrorHandler
Dim strSQL As String
Dim ssql2 As String
'Check to see if we are going to display either the department or an individual employee
If indiv = False Then
'Department was selected
ssql2 = "SELECT DepartName FROM tblDepartInfo WHERE DepartNum =" & DataGrid3.Text
Set goGetdepNme = New ADODB.Connection
Set recGetDepNme = New ADODB.Recordset
goGetdepNme.CursorLocation = adUseClient
goGetdepNme.Open "Provider = Microsoft.Jet.OLEDB.4.0;Persist Security Info = False;Data Source = F:\mydb.mdb"
recGetDepNme.Open ssql2, goGetdepNme, adOpenStatic, adLockOptimistic
txtDepartName.Text = recGetDepNme!departname & ""
strSQL = "SELECT EmpNum, EmployeeNme From tblEmployee WHERE DepartNum = " & DataGrid3.Text & " AND ActiveInactive=0"
txtDepartNum.Text = DataGrid3.Text
Adodc2.Enabled = True
Adodc2.RecordSource = strSQL
Adodc2.Refresh
Set DataGrid2.DataSource = Adodc2
ElseIf indiv = True Then
'Individual Employee Was Selected
ssql2 = "SELECT * FROM tblEmployee WHERE EmpNum =" & DataGrid3.Text 'Grabs the Employees Number from the Selected DataGrid3 Text
Set goGetdepNme = New ADODB.Connection
Set recGetDepNme = New ADODB.Recordset
goGetdepNme.CursorLocation = adUseClient
goGetdepNme.Open "Provider = Microsoft.Jet.OLEDB.4.0;Persist Security Info = False;Data Source = F:\mydb.mdb"
recGetDepNme.Open ssql2, goGetdepNme, adOpenStatic, adLockOptimistic
txtDepartName.Text = recGetDepNme!departname & ""
txtDepartNum.Text = recGetDepNme!departnum & ""
txtEmployeeNme.Text = recGetDepNme!EmployeeNme & ""
txtEmpNum.Text = recGetDepNme!empnum & ""
strSQL = "SELECT EmpNum, EmployeeNme From tblEmployee WHERE DepartNum = " & DataGrid3.Text & " AND ActiveInactive=0"
Adodc2.Enabled = False
End If
DBErrorHandler:
MsgBox err.description, err.number
resume next
exit sub
End Sub
Controls On The Form Are As Follows:
optDepartment 'Option Button For Selecting A Department
optEmployee 'Option Button For Selecting A Single Employee
Datagrid3 'Datagrid Control - Displays either Employee Number & Employee Name OR Department Number & Department Name
Datagrid2 'Datagrid Control - Displays only Employee Number & Employee Name IF a Department was Selected, other wise it's disabled if selecting a
'single employee
Datagrid1 'Datagrid Control - Displays the schedule for either the department or employee
Problem Description:
The code display above does not trap any errors, when a user selects the department name or employee name it gives a run time error and exits
the application. The user is supposed to select the DepartNum field if selecting a department or EmpNum field if selecting a individual
employee. If the user does not select a DepartNum or EmpNum, the ssql2 errors out and gives the following error message:
Run Time Error '-2147217904'(8004e10)':
No Value Given For One Or More Required Parameters
I know what this error is and what's causing, I just can't figure out how to tell the user that "Hey you selected a Department Name and not the
Department Number, try again" Or "Hey you selected an Employee Name and not the Employee Number, try again!"