relax4delicutfew
Programmer
I am developing a database where I need to search through the data based on different critera. I am using combo boxes to do this, however I have run into a problem. I can the first combo box to search correctly, however when successive combo boxes are added they wont search correctly. Right now I have two combo boxes, and I want to be able to use each independently as well as a joint search. If anyone can help me it would be greatly appreciated.
Here is the code I am currently working with:
Thanks Very Much
Craig
Here is the code I am currently working with:
Code:
Option Compare Database
Option Explicit
Private Const strSQL1 = "SELECT CaseID FROM qryCombo1 WHERE"
Private Const strSQL2 = " RouteNumber = '"
Private Const strSQL3 = " PostedSpeed = '"
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 cboSpeed_AfterUpdate()
If Me!cboSpeed.Value > 0 Then
Call FillList
End If
End Sub
Private Sub FillList()
strSQL5 = strSQL2 & Me!cboRoute.Value & "'"
strSQL6 = strSQL3 & Me!cboSpeed.Value & "'"
If Len(Me!cboRoute.Value & "") > 0 Then
Me!lstCrashes.RowSource = strSQL1 & strSQL5
Me!lstCrashes.Requery
ElseIf Len(Me!cboSpeed.Value & "") > 0 And Len(Me!cboRoute.Value & "") > 0 Then
Me!lstCrashes.RowSource = strSQL1 & strSQL5 & strSQL4 & strSQL6
Me!lstCrashes.Requery
ElseIf Len(Me!cboSpeed.Value & "") > 0 And Len(Me!cboRoute.Value & "") = 0 Then
Me!lstCrashes.RowSource = strSQL1 & strSQL6
Me!lstCrashes.Requery
End If
End Sub
Private Sub Form_Activate()
If Me!cboRoute.Value Like "***" Or Me!cboSpeed.Value Like "***" Then
Call FillList
End If
End Sub
Thanks Very Much
Craig