I have a form with 2 combo boxes, the first box is a name selection and the second box lists all companies that employ that name. The cascading part of the combo boxes works great.
I used the following code on the first combo box, employee name:
Private Sub cboEmployee_AfterUpdate()
Me.cboClient.RowSource = "SELECT DISTINCT [ClientName] FROM AccidentTable WHERE [EmployeeLastName] = '" & Me.cboEmployee & "'; "
Me.cboClient.Requery
End Sub
When the user makes a selection from second combo box, which is filtered by the above code. The value strClient is never populated when the report executes. See code below:
Private Sub Command2_Click()
On Error GoTo Err_Command2_Click
Dim strClient As String
Dim strEmmployee As String
Dim stDocName As String
' Build criteria string for Employee Last Name field
If IsNull(Me.cboEmployee.Value) Then
strEmployee = "Like '*'"
Else
strEmployee = "= '" & Me.cboEmployee.Value & "'"
End If
' Build criteria string for Client field
If IsNull(Me.cboClient.Value) Then
strClient = "Like '*'"
Else
strClient = "= '" & Me.cboClient.Value & "'"
End If
stDocName = "rptIncidentReport"
' Combine criteria strings into a WHERE claus for the filter
strFilter = "[EmployeeLastName] " & strEmployee & " and [ClientName] " & strClient
'This function closes the report if the report is open and then re-opens the report.
Set accobj = Application.CurrentProject.AllReports.Item(stDocName)
If accobj.IsLoaded Then
If accobj.CurrentView = acCurViewPreview Then
DoCmd.Close acReport, stDocName
DoCmd.OpenReport stDocName, acPreview, , strFilter
End If
Else
DoCmd.OpenReport stDocName, acPreview, , strFilter
End If
What am I missing to get the strClient populated with the selection from the second combo box?
Thanks
I used the following code on the first combo box, employee name:
Private Sub cboEmployee_AfterUpdate()
Me.cboClient.RowSource = "SELECT DISTINCT [ClientName] FROM AccidentTable WHERE [EmployeeLastName] = '" & Me.cboEmployee & "'; "
Me.cboClient.Requery
End Sub
When the user makes a selection from second combo box, which is filtered by the above code. The value strClient is never populated when the report executes. See code below:
Private Sub Command2_Click()
On Error GoTo Err_Command2_Click
Dim strClient As String
Dim strEmmployee As String
Dim stDocName As String
' Build criteria string for Employee Last Name field
If IsNull(Me.cboEmployee.Value) Then
strEmployee = "Like '*'"
Else
strEmployee = "= '" & Me.cboEmployee.Value & "'"
End If
' Build criteria string for Client field
If IsNull(Me.cboClient.Value) Then
strClient = "Like '*'"
Else
strClient = "= '" & Me.cboClient.Value & "'"
End If
stDocName = "rptIncidentReport"
' Combine criteria strings into a WHERE claus for the filter
strFilter = "[EmployeeLastName] " & strEmployee & " and [ClientName] " & strClient
'This function closes the report if the report is open and then re-opens the report.
Set accobj = Application.CurrentProject.AllReports.Item(stDocName)
If accobj.IsLoaded Then
If accobj.CurrentView = acCurViewPreview Then
DoCmd.Close acReport, stDocName
DoCmd.OpenReport stDocName, acPreview, , strFilter
End If
Else
DoCmd.OpenReport stDocName, acPreview, , strFilter
End If
What am I missing to get the strClient populated with the selection from the second combo box?
Thanks