Solved

Creating a Search Field

Posted on 2011-02-24
7
290 Views
Last Modified: 2012-08-13
Hi

I am creating a search field to find records in my database using an unbound text called txtSearch, a command button called cmdSearch, and a the field cboSIMNO as the search field. Pleas see below.

Private Sub cmdSearch_Click()
    Dim strSIMNo As String
    Dim strSearch As String
   

    If IsNull(Me![txtSearch]) Or (Me![txtSearch]) = "" Then
        MsgBox "Please enter a value!", vbOKOnly, "Invalid Search!"
        Me![txtSearch].SetFocus
    Exit Sub
End If
       
    DoCmd.ShowAllRecords
    DoCmd.GoToControl "cboSIMPhoneNo"
    DoCmd.FindRecord Me!txtSearch
       
    Me.cboSIMPhoneNo.SetFocus
    strSIMNo = Me.cboSIMPhoneNo.Text
    Me.txtSearch.SetFocus
    strSearch = Me.txtSearch.Text

I know that i have records in my database with the same details but it will only show the first record. How do i get it to show the other records? I need to use a loop somewhere or find next record but i am not sure how to add it into my code.

kind regards
DGI
0
Comment
Question by:dgi001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 250 total points
ID: 34971743
you may just need to apply a filter to show all the records..


Private Sub cmdSearch_Click()
    Dim strSIMNo As String
    Dim strSearch As String
   

    If IsNull(Me![txtSearch]) Or (Me![txtSearch]) = "" Then
        MsgBox "Please enter a value!", vbOKOnly, "Invalid Search!"
        Me![txtSearch].SetFocus
    Exit Sub
End If

me.filter="[Fieldname] = '" & me.txtSearch & "'"
me.filteron=true

end sub

change "[Fieldname]" with actual name of the field



0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 34971756
if the [Fieldname] is Number Data Type, use this

me.filter="[Fieldname] = " & me.txtSearch
me.filteron=true
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 34971771
if you want to do a search on partial info entered, use something like this


me.filter="[Fieldname]  like '*" & me.txtSearch & "*'"
me.filteron=true
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 77

Expert Comment

by:peter57r
ID: 34971776
Use the form filter instead.

Private Sub cmdSearch_Click()
    Dim strSIMNo As String
    Dim strSearch As String

    DoCmd.ShowAllRecords

    If IsNull(Me![txtSearch]) Or (Me![txtSearch]) = "" Then
        MsgBox "Please enter a value!", vbOKOnly, "Invalid Search!"
        Me![txtSearch].SetFocus
    Exit Sub
End If
       
      me.filter = "strSIMNo ='" & Me.txtSearch &"'"
      me.filteron = true
end sub
0
 

Author Comment

by:dgi001
ID: 34998374
HI Capricorn1

That worked but i need it to search more than one criteria. i am adding this

Me.Filter = "[SIMPhoneNO] = '" & Me.txtSearch & "'" And "[SIMStatus] = 'Active' "

but i receive an error "Run-time error 13, type mismatch"

Any Ideas?

If you feel i need to open a separate question for this,i will.

Kind regards
Nick
0
 
LVL 77

Assisted Solution

by:peter57r
peter57r earned 250 total points
ID: 34998901
Me.Filter = "[SIMPhoneNO] = '" & Me.txtSearch & "' And [SIMStatus] = 'Active' "

If you still get a problem you must check the datatype of SimStatus.
0
 

Author Closing Comment

by:dgi001
ID: 35025417
Hi Guys

That worked great.

Thank you

Kind regards
DGI
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question