Results 1 to 5 of 5
  1. #1
    ortizimo is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jun 2017
    Location
    FL
    Posts
    88

    Cant Clear RecordSource after Search

    tried for hours to figure out how to make a clear button that clears the RecordSource after a search...if I take it out the Me.RecordSource the cancel with Me.Requery works...if I leave it txtSearch field clears but Me.Requery doesnt work so the form stays at what it found instead of going back to all the records.

    '---------------------------------------------
    ' 05. Cancel button
    '---------------------------------------------
    Private Sub cmdCancel_Click()


    Me.Requery
    Me.txtSearch = ""
    Me.txtSearch.BackColor = vbWhite
    Me.txtSearch.SetFocus
    End Sub

    '--------------------------------------------
    ' Form_Load
    '---------------------------------------------
    Private Sub Form_Load()

    Dim strSearch As String
    Me.txtSearch.BackColor = vbWhite
    strSearch = "SELECT * FROM tblQuestion WHERE ((Question Like ""*" & strSearch & "*"") OR (Possible1 like ""*" & strSearch & "*"") OR (Possible2 like ""*" & strSearch & "*"") OR (Possible3 like ""*" & strSearch & "*"") OR (Possible4 like ""*" & strSearch & "*""))"
    Me.RecordSource = strSearch
    Me.txtSearch.SetFocus
    End Sub

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    if you change the rowsource or record source of an object you should also requery the form

    me.requery

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    If you want all records after clicking the clear button:

    Me.RecordSource = "SELECT * FROM tblQuestion"

    In my experience no requery is necessary after setting a row/record source.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    ortizimo is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jun 2017
    Location
    FL
    Posts
    88
    Quote Originally Posted by pbaldy View Post
    If you want all records after clicking the clear button:

    Me.RecordSource = "SELECT * FROM tblQuestion"

    In my experience no requery is necessary after setting a row/record source.
    Thanks...that worked!

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Clear previous data from search
    By cbramsey in forum Forms
    Replies: 6
    Last Post: 08-18-2017, 09:21 AM
  2. Clear Search Form
    By armyofdux in forum Forms
    Replies: 9
    Last Post: 03-03-2015, 06:24 AM
  3. Search field will not clear
    By SemiAuto40 in forum Programming
    Replies: 1
    Last Post: 10-13-2011, 08:23 PM
  4. How to clear a search form ?
    By Trojnfn in forum Access
    Replies: 2
    Last Post: 10-05-2011, 01:12 PM
  5. Search and Clear button
    By polk383 in forum Programming
    Replies: 1
    Last Post: 08-30-2006, 08:51 AM

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