Public faytProducts As New FindAsYouTypeCombo
Private Sub...
Private Sub txtSearch_Change()
Const src As String = "select data.* from data"
Dim txt As String
Dim new_src As String
txt = Me.txtSearch.Text
new_src = src
If Len(txt) <> 0 Then
new_src = new_src & " where [project name] like '" & txt & "*'"
End If
Me.RecordSource = new_src
With Me.txtSearch
.Value = txt
.SelStart = Len(txt)
End With
End Sub
In my class example you simply pass in the fields you want to search. No need for extra code.But How to modify it to let me search by more criterias like [Task Name] and [Assigned to] not [project name] only
Thanks for trying help me.I know that you are an expert in AccessIn my class example you simply pass in the fields you want to search. No need for extra code.
Thanks a lot for help menew_src = new_src & " where [project name] like '" & txt & "*' OR [task name] like '" & txt & "*'"
'Need to declare a variable at top of module
Private FAYT_Form As FindAsYouTypeForm
Private Sub Form_Load()
Set FAYT_Form = New FindAsYouTypeForm
FAYT_Form.Initialize Me, Me.txtFilter, ffrm_Anywhereinstring, True, "ProductName"
End Sub
Dates require # delimiters and in mm/dd/yyyy or yyyy-mm-dd format.Thanks a lot for help me
That's worked with me, but not work when I search by any date in the Startdate field is there any thing to do??
Thanks a lot
Excuse me, What did you mean? what shoul I write in the code and where?Dates require # delimiters and in mm/dd/yyyy or yyyy-mm-dd format.
Public Sub FilterList(FilterValue As Variant)
On Error GoTo errLable
Dim rsTemp As DAO.Recordset
Dim FilterString As String
Set rsTemp = mRsOriginalList.OpenRecordset
Select Case mColumnType
Case ColumnType.datecolumn
FilterValue = Format(FilterValue, "MM/DD/YYYY")
FilterString = "#" & FilterValue & "#"
Case ColumnType.TextColumn
FilterValue = Replace(FilterValue, "'", "''")
FilterString = "'" & FilterValue & "'"
Case ColumnType.NumericColumn
FilterString = FilterValue
End Select
If mFilterType = Exact_Records Then
FilterString = mFilterPrefix & " = " & FilterString
ElseIf mFilterType = Like_Records Then
FilterString = mFilterPrefix & " Like '*" & FilterValue & "*'"
End If
'Debug.Print FilterString
mFilterString = FilterString
rsTemp.Filter = FilterString
Set rsTemp = rsTemp.OpenRecordset
If rsTemp.RecordCount > 0 Then
Set mListbox.Recordset = rsTemp
mListbox.Selected(0) = True
mListbox.Value = mListbox.Column(0)
mFilterString = FilterString
Else
MsgBox "No Records Found Matching the Filter: " & FilterString
Call unFilterList
End If
Exit Sub
errLable:
If Err.Number = 3061 Then
MsgBox "Will not Filter. Verify filter string is Correct."
Else
MsgBox Err.Number & " " & Err.Description
End If
End Sub
Private Sub mTextBox_AfterUpdate()
If Not Trim(mTextBox & " ") = "" Then
Call FilterList(mTextBox.Value)
Else
mFilterString = ""
End If
End Sub
I tried in the attachement file but not work.Please what is the issue?Here is a cut down version
To use and search any amount of TEXT fields
Code:'Need to declare a variable at top of module Private FAYT_Form As FindAsYouTypeForm Private Sub Form_Load() Set FAYT_Form = New FindAsYouTypeForm FAYT_Form.Initialize Me, Me.txtFilter, ffrm_Anywhereinstring, True, "ProductName" End Sub
In the initialize event
1. Me is the reference to the form to filter. If it is a subform you need to pass a reference to the subform
2. Me.TextFilter is the textbox that you type into
3. ffrm_Anywhereinstring is an enum that lets you pick how to search
4. True handles international characters
5. I only list one field "ProductName" but you can list as many as you want seperated by commas
If you are searching a date this is not going to work. You should be doing a different kind of search for dates. You should not have a single textbox for text or dates. It is doable but clunky.
Option Compare Database
Option Explicit
'Need to declare a variable at top of module
Private FAYT_Form As FindAsYouTypeForm
Private Sub Form_Load()
Set FAYT_Form = New FindAsYouTypeForm
FAYT_Form.Initialize Me, Me.txtSearch, ffrm_Anywhereinstring, True, "[Project Name]", "[Task Name]", "[Assigned to]"
End Sub
Thank you very muchhere again is the Simple search, with multiple field search.