relax4delicutfew
Programmer
I have a form which currently has 2 combo boxes, and I use them to sort data from a query I created. My goal is to be able to use the boxes to search independent of one another and in conjunction with one other. I have attached my code. Any help would be greatly appreciated.
Thanks
Craig
Code:
Option Compare Database
Option Explicit
Private Const strSQL1 = "SELECT CaseID, Milepost, Purpose, GuardrailType, TerminalType, HardwareComments " & _
"FROM qryCombo1 WHERE"
Private Const strSQL2 = " RouteNumber = '"
Private Const strSQL3 = " Direction = '"
Private Const strSQL4 = "And"
Private strSQL5 As String
Private strSQL6 As String
Private Sub cboRoute_AfterUpdate()
If Me!cboRoute.Value > 0 Then
Call FillList
End If
End Sub
Private Sub cboDirection_AfterUpdate()
If Me!cboDirection.Value > 0 Then
Call FillList
End If
End Sub
Private Sub FillList()
strSQL5 = strSQL2 & Me!cboRoute.Value
strSQL6 = strSQL3 & Me!cboDirection.Value
If Len(Me!cboRoute.Value & "") > 0 Then
Me!lstCrashes.RowSource = strSQL1 & strSQL5
Me!lstCrashes.Requery
End If
If Len(Me!cboDirection.Value & "") > 0 And Len(Me!cboRoute.Value & "") = 0 Then
Me!lstCrashes.RowSource = strSQL1 & strSQL6
Me!lstCrashes.Requery
End If
If Len(Me!cboDirection.Value & "") > 0 And Len(Me!cboRoute.Value & "") > 0 Then
Me!lstCrashes.RowSource = strSQL1 & strSQL5 & strSQL4 & strSQL6
Me!lstCrashes.Requery
End If
End Sub
Private Sub Form_Activate()
If Me!cboRoute.Value Like "***" Or Me!cboDirection.Value Like "***" Then
Call FillList
End If
End Sub
Thanks
Craig