I've got a search form based on the following code. After much help from Mile-O-Phile I've been able to get it so that when the user enters an age in an unbound txtbox, a range of +/- 5 years of the date of birth populates 11 unbound txtboxes (each holds a different year.) The below searh works great for everything else, but what I need it to do is look at the populated txtboxes and if one of them matches a person's DOB, then display the results in the results txtbox.
If this doesn't make sense please let me know.
As always, Thanks.
-Phil
http://www.geocities.com/philpoole16
Option Compare Database
Private Sub Clear_Click()
frmSearchForm = vbNullString
lstCustInfo.RowSource = ""
End Sub
Private Sub cmdSearch_Click()
'Set the Dimensions of the Module
Dim strSQL As String, strOrder As String, strWhere As String
Dim dbNm As Database
Dim qryDef As QueryDef
Set dbNm = CurrentDb()
'Constant Select Racement for the RowSource
strSQL = "SELECT BookingSheet.BookingSheetNumber, BookingSheet.First, BookingSheet.Middle, BookingSheet.Last, BookingSheet.Race, BookingSheet.Sex, BookingSheet.DOB, BookingSheet.Height, BookingSheet.Weight, BookingSheet.HairColor, BookingSheet.EyeColor, BookingSheet.ScarsMarksTattoos " & _
"FROM BookingSheet"
strWhere = "WHERE"
strOrder = "ORDER BY BookingSheet.BookingSheetNumber;"
'Set the WHERE clause for the Listbox RowSource if information has been entered into a field on the form
If Not IsNull(Me.txtFirst) Then '<--If the textbox txtFirst contains no data THEN do nothing
strWhere = strWhere & " (BookingSheet.First) Like '*" & Me.txtFirst & "*' AND" '<--otherwise, apply the LIKE statment to the QueryDef
End If
If Not IsNull(Me.txtLast) Then
strWhere = strWhere & " (BookingSheet.Last) Like '*" & Me.txtLast & "*' AND"
End If
If Not IsNull(Me.txtMiddle) Then
strWhere = strWhere & " (BookingSheet.Middle) Like '*" & Me.txtMiddle & "*' AND"
End If
If Not IsNull(Me.txtRace) Then
strWhere = strWhere & " (BookingSheet.Race) Like '*" & Me.txtRace & "*' AND"
End If
If Not IsNull(Me.cmbSex) Then
strWhere = strWhere & " (BookingSheet.Sex) Like '*" & Me.cmbSex & "*' AND"
End If
If Not IsNull(Me.txtHeight) Then
strWhere = strWhere & " (BookingSheet.Height) Like '*" & Me.txtHeight & "*' AND"
End If
If Not IsNull(Me.cmbEyeColor) Then
strWhere = strWhere & " (BookingSheet.EyeColor) Like '*" & Me.cmbEyeColor & "*' AND"
End If
If Not IsNull(Me.cmbHair) Then
strWhere = strWhere & " (BookingSheet.HairColor) Like '*" & Me.cmbHair & "*' AND"
End If
If Not IsNull(Me.smt) Then
strWhere = strWhere & " (BookingSheet.ScarsMarksTattoos) Like '*" & Me.smt & "*' AND"
End If
If Not IsNull(Me.txtmin1) Then
strWhere = strWhere & " (BookingSheet.DOB) Like '*" & Me.txtmin1 & "*' AND"
End If
If Not IsNull(Me.txtmin2) Then
strWhere = strWhere & " (BookingSheet.DOB) Like '*" & Me.txtmin2 & "*' AND"
End If
If Not IsNull(Me.txtmin3) Then
strWhere = strWhere & " (BookingSheet.DOB) Like '*" & Me.txtmin3 & "*' AND"
End If
If Not IsNull(Me.txtmin4) Then
strWhere = strWhere & " (BookingSheet.DOB) Like '*" & Me.txtmin4 & "*' AND"
End If
If Not IsNull(Me.txtmin5) Then
strWhere = strWhere & " (BookingSheet.DOB) Like '*" & Me.txtmin5 & "*' AND"
End If
If Not IsNull(Me.txtmax1) Then
strWhere = strWhere & " (BookingSheet.DOB) Like '*" & Me.txtmax1 & "*' AND"
End If
If Not IsNull(Me.txtmax2) Then
strWhere = strWhere & " (BookingSheet.DOB) Like '*" & Me.txtmax2 & "*' AND"
End If
If Not IsNull(Me.txtmax3) Then
strWhere = strWhere & " (BookingSheet.DOB) Like '*" & Me.txtmax3 & "*' AND"
End If
If Not IsNull(Me.txtmax4) Then
strWhere = strWhere & " (BookingSheet.DOB) Like '*" & Me.txtmax4 & "*' AND"
End If
If Not IsNull(Me.txtmax5) Then
strWhere = strWhere & " (BookingSheet.DOB) Like '*" & Me.txtmax5 & "*' AND"
End If
If Not IsNull(Me.txtage) Then
strWhere = strWhere & " (BookingSheet.DOB) Like '*" & Me.txtage & "*' AND"
End If
'Remove the last AND from the SQL statment
strWhere = Mid(strWhere, 1, Len(strWhere) - 5)
'Pass the SQL to the RowSource of the listbox
Me.lstCustInfo.RowSource = strSQL & " " & strWhere & "" & strOrder
End Sub
Private Sub lstCustInfo_DblClick(Cancel As Integer)
'Open BookingSheet based on the Booking Sheet Number from lstCustInfo listbox
DoCmd.OpenForm "BookingSheet", , , "[BookingSheetNumber] = " & Me.lstCustInfo, , acDefault
End Sub
Private Sub txtmin2_AfterUpdate()
txtmin2 = (Year(Date) - Me.txtYear) + 2 & " "
End Sub
Private Sub txtmin2_Enter()
txtmin2 = (Year(Date) - Me.txtYear) + 2 & " "
End Sub
Private Sub txtYear_AfterUpdate()
Dim intCounter As Integer, strList As String
If IsNull(Me.txtYear) Then Exit Sub
strList = strList & (Year(Date) - Me.txtYear) + 1 & " "
Me.txtmin1 = Trim(strList)
txtmin2 = (Year(Date) - Me.txtYear) + 2 & " "
txtmin3 = (Year(Date) - Me.txtYear) + 3 & " "
txtmin4 = (Year(Date) - Me.txtYear) + 4 & " "
txtmin5 = (Year(Date) - Me.txtYear) + 5 & " "
txtmax1 = (Year(Date) - Me.txtYear) - 1 & " "
txtmax2 = (Year(Date) - Me.txtYear) - 2 & " "
txtmax3 = (Year(Date) - Me.txtYear) - 3 & " "
txtmax4 = (Year(Date) - Me.txtYear) - 4 & " "
txtmax5 = (Year(Date) - Me.txtYear) - 5 & " "
txtage = (Year(Date) - Me.txtYear) - 0 & " "
End Sub
If this doesn't make sense please let me know.
As always, Thanks.
-Phil
http://www.geocities.com/philpoole16
Option Compare Database
Private Sub Clear_Click()
frmSearchForm = vbNullString
lstCustInfo.RowSource = ""
End Sub
Private Sub cmdSearch_Click()
'Set the Dimensions of the Module
Dim strSQL As String, strOrder As String, strWhere As String
Dim dbNm As Database
Dim qryDef As QueryDef
Set dbNm = CurrentDb()
'Constant Select Racement for the RowSource
strSQL = "SELECT BookingSheet.BookingSheetNumber, BookingSheet.First, BookingSheet.Middle, BookingSheet.Last, BookingSheet.Race, BookingSheet.Sex, BookingSheet.DOB, BookingSheet.Height, BookingSheet.Weight, BookingSheet.HairColor, BookingSheet.EyeColor, BookingSheet.ScarsMarksTattoos " & _
"FROM BookingSheet"
strWhere = "WHERE"
strOrder = "ORDER BY BookingSheet.BookingSheetNumber;"
'Set the WHERE clause for the Listbox RowSource if information has been entered into a field on the form
If Not IsNull(Me.txtFirst) Then '<--If the textbox txtFirst contains no data THEN do nothing
strWhere = strWhere & " (BookingSheet.First) Like '*" & Me.txtFirst & "*' AND" '<--otherwise, apply the LIKE statment to the QueryDef
End If
If Not IsNull(Me.txtLast) Then
strWhere = strWhere & " (BookingSheet.Last) Like '*" & Me.txtLast & "*' AND"
End If
If Not IsNull(Me.txtMiddle) Then
strWhere = strWhere & " (BookingSheet.Middle) Like '*" & Me.txtMiddle & "*' AND"
End If
If Not IsNull(Me.txtRace) Then
strWhere = strWhere & " (BookingSheet.Race) Like '*" & Me.txtRace & "*' AND"
End If
If Not IsNull(Me.cmbSex) Then
strWhere = strWhere & " (BookingSheet.Sex) Like '*" & Me.cmbSex & "*' AND"
End If
If Not IsNull(Me.txtHeight) Then
strWhere = strWhere & " (BookingSheet.Height) Like '*" & Me.txtHeight & "*' AND"
End If
If Not IsNull(Me.cmbEyeColor) Then
strWhere = strWhere & " (BookingSheet.EyeColor) Like '*" & Me.cmbEyeColor & "*' AND"
End If
If Not IsNull(Me.cmbHair) Then
strWhere = strWhere & " (BookingSheet.HairColor) Like '*" & Me.cmbHair & "*' AND"
End If
If Not IsNull(Me.smt) Then
strWhere = strWhere & " (BookingSheet.ScarsMarksTattoos) Like '*" & Me.smt & "*' AND"
End If
If Not IsNull(Me.txtmin1) Then
strWhere = strWhere & " (BookingSheet.DOB) Like '*" & Me.txtmin1 & "*' AND"
End If
If Not IsNull(Me.txtmin2) Then
strWhere = strWhere & " (BookingSheet.DOB) Like '*" & Me.txtmin2 & "*' AND"
End If
If Not IsNull(Me.txtmin3) Then
strWhere = strWhere & " (BookingSheet.DOB) Like '*" & Me.txtmin3 & "*' AND"
End If
If Not IsNull(Me.txtmin4) Then
strWhere = strWhere & " (BookingSheet.DOB) Like '*" & Me.txtmin4 & "*' AND"
End If
If Not IsNull(Me.txtmin5) Then
strWhere = strWhere & " (BookingSheet.DOB) Like '*" & Me.txtmin5 & "*' AND"
End If
If Not IsNull(Me.txtmax1) Then
strWhere = strWhere & " (BookingSheet.DOB) Like '*" & Me.txtmax1 & "*' AND"
End If
If Not IsNull(Me.txtmax2) Then
strWhere = strWhere & " (BookingSheet.DOB) Like '*" & Me.txtmax2 & "*' AND"
End If
If Not IsNull(Me.txtmax3) Then
strWhere = strWhere & " (BookingSheet.DOB) Like '*" & Me.txtmax3 & "*' AND"
End If
If Not IsNull(Me.txtmax4) Then
strWhere = strWhere & " (BookingSheet.DOB) Like '*" & Me.txtmax4 & "*' AND"
End If
If Not IsNull(Me.txtmax5) Then
strWhere = strWhere & " (BookingSheet.DOB) Like '*" & Me.txtmax5 & "*' AND"
End If
If Not IsNull(Me.txtage) Then
strWhere = strWhere & " (BookingSheet.DOB) Like '*" & Me.txtage & "*' AND"
End If
'Remove the last AND from the SQL statment
strWhere = Mid(strWhere, 1, Len(strWhere) - 5)
'Pass the SQL to the RowSource of the listbox
Me.lstCustInfo.RowSource = strSQL & " " & strWhere & "" & strOrder
End Sub
Private Sub lstCustInfo_DblClick(Cancel As Integer)
'Open BookingSheet based on the Booking Sheet Number from lstCustInfo listbox
DoCmd.OpenForm "BookingSheet", , , "[BookingSheetNumber] = " & Me.lstCustInfo, , acDefault
End Sub
Private Sub txtmin2_AfterUpdate()
txtmin2 = (Year(Date) - Me.txtYear) + 2 & " "
End Sub
Private Sub txtmin2_Enter()
txtmin2 = (Year(Date) - Me.txtYear) + 2 & " "
End Sub
Private Sub txtYear_AfterUpdate()
Dim intCounter As Integer, strList As String
If IsNull(Me.txtYear) Then Exit Sub
strList = strList & (Year(Date) - Me.txtYear) + 1 & " "
Me.txtmin1 = Trim(strList)
txtmin2 = (Year(Date) - Me.txtYear) + 2 & " "
txtmin3 = (Year(Date) - Me.txtYear) + 3 & " "
txtmin4 = (Year(Date) - Me.txtYear) + 4 & " "
txtmin5 = (Year(Date) - Me.txtYear) + 5 & " "
txtmax1 = (Year(Date) - Me.txtYear) - 1 & " "
txtmax2 = (Year(Date) - Me.txtYear) - 2 & " "
txtmax3 = (Year(Date) - Me.txtYear) - 3 & " "
txtmax4 = (Year(Date) - Me.txtYear) - 4 & " "
txtmax5 = (Year(Date) - Me.txtYear) - 5 & " "
txtage = (Year(Date) - Me.txtYear) - 0 & " "
End Sub
Last edited: