Results 1 to 2 of 2
  1. #1
    ahmed sami is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Oct 2014
    Location
    Baghdad Iraq
    Posts
    8

    Search Button

    Hi everybody.... I have built up a MS form that stores various info. but unfortunately I overlooked the issue of how to search these info or records. The search field in the button is rather impractical because it starts to search everything in the page that matches every single character I wrote in the search field. I want to put a VBA code that search for a certain record in specific field not all fields. I have found this code:



    Dim strSearch As Variant
    Dim strText As Variant
    If IsNull(txtSearch) = True Then
    MsgBox ("Please enter a keyword")
    End If
    strText = Me.txtSearch.Value
    strSearch = "SELECT * from tblMain where ( [SubjectLetter] like ""*" & strText & "*"")"
    Me.RecordSource = strSearch
    DoCmd.FindNext
    This code is working well, but has the following defects:
    1. It does not find the next matching records, or in other words, if there are duplicates, it just find the first and ignore the others.
    2. Once the button is clicked, the sequence of the available saved records goes to 1 of 2.
    Thanks in advance.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,644
    Why set the form RecordSource? Why not just set form Filter and FilterOn properties. Review: http://www.allenbrowne.com/ser-62code.html
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Search Button to search entire records VBA
    By excellenthelp in forum Access
    Replies: 5
    Last Post: 06-18-2014, 02:54 PM
  2. Replies: 5
    Last Post: 07-13-2012, 01:15 AM
  3. Replies: 12
    Last Post: 03-22-2012, 02:48 AM
  4. Search Button
    By bomber72 in forum Forms
    Replies: 6
    Last Post: 08-03-2011, 11:44 AM
  5. Search Button
    By injanib in forum Forms
    Replies: 1
    Last Post: 01-16-2011, 07:36 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums