B
Barry
I am building a search form that will allow the selection of data to search
by, ie company, QuoteNumber, QuoteDate. The string portion (CompanyName)
allows the use of like and "*". When the field is changed and is empty the
entire recordset is returned in the listbox. However, I cannot seem to
repeat that functionality with the integer (QuoteID) or date (QuoteDate)
criteria. The code I am using will follow below. The questions are for the
Case 2 and Case 3 portions of the select case statement. I have tried to
use: Where = "[QuoteID] like " & txtToSearch & "*" but if you put the number
1 in the strSearch field the search returns blank and I would expect quotes
numbered 1, 10, 11, 12, 100, 101 etc.
Private Sub strSearch_Change()
'Setup variables
Dim strSQL As String
Dim Where As String
Dim SearchBy As Integer
Dim txtToSearch As Variant
'Combo box for field to search. String to search
SearchBy = Me!cboSearchBy
txtToSearch = Me!strSearch.Text
'Setup the Where clause
Select Case (SearchBy)
Case 1
Where = "[CompanyName] Like '" & txtToSearch & "*" & "'"
Case 2
Where = "[QuoteID] Like " & txtToSearch
Case 3
Where = "[QuoteDate] Like #" & txtToSearch & "#"
End Select
'Construct SQL to be used as listbox RowSource
strSQL = "Select tblQuotesBattery.QuoteID, tblCustomers.CompanyName,
tblQuotesBattery.QuoteDate, tblQuotesBattery.CustomerID" & _
" FROM tblCustomers INNER JOIN tblQuotesBattery" & _
" ON tblCustomers.CustomerID = tblQuotesBattery.CustomerID" & _
" Where " & Where
'Set the RowSource
lstQuoteBattery.RowSource = strSQL
lstQuoteBattery.Requery
Me!strSearch.SetFocus
End Sub
Your comments are greatly appreciated.
Thanks,
Barry
by, ie company, QuoteNumber, QuoteDate. The string portion (CompanyName)
allows the use of like and "*". When the field is changed and is empty the
entire recordset is returned in the listbox. However, I cannot seem to
repeat that functionality with the integer (QuoteID) or date (QuoteDate)
criteria. The code I am using will follow below. The questions are for the
Case 2 and Case 3 portions of the select case statement. I have tried to
use: Where = "[QuoteID] like " & txtToSearch & "*" but if you put the number
1 in the strSearch field the search returns blank and I would expect quotes
numbered 1, 10, 11, 12, 100, 101 etc.
Private Sub strSearch_Change()
'Setup variables
Dim strSQL As String
Dim Where As String
Dim SearchBy As Integer
Dim txtToSearch As Variant
'Combo box for field to search. String to search
SearchBy = Me!cboSearchBy
txtToSearch = Me!strSearch.Text
'Setup the Where clause
Select Case (SearchBy)
Case 1
Where = "[CompanyName] Like '" & txtToSearch & "*" & "'"
Case 2
Where = "[QuoteID] Like " & txtToSearch
Case 3
Where = "[QuoteDate] Like #" & txtToSearch & "#"
End Select
'Construct SQL to be used as listbox RowSource
strSQL = "Select tblQuotesBattery.QuoteID, tblCustomers.CompanyName,
tblQuotesBattery.QuoteDate, tblQuotesBattery.CustomerID" & _
" FROM tblCustomers INNER JOIN tblQuotesBattery" & _
" ON tblCustomers.CustomerID = tblQuotesBattery.CustomerID" & _
" Where " & Where
'Set the RowSource
lstQuoteBattery.RowSource = strSQL
lstQuoteBattery.Requery
Me!strSearch.SetFocus
End Sub
Your comments are greatly appreciated.
Thanks,
Barry