Results 1 to 3 of 3
  1. #1
    Vetgeorge is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Florida
    Posts
    29

    Clear button on a search form partially working

    I have a "Clear" button on a search form that only clears the search fields on the main form. I would like it to also clear the query results I have as a subform on this form and return it to it's original state.
    What do I need to change?

    The search form is used to look up medical names and codes based upon five categories: Disease, Etiology, Morphology, Procedure & Topography. The search fields can be used singly or have entries in each field and the query updates to find your search parameters. It works except for my clear button.

    Tables:
    tblCategory
    tblSNOMED

    Forms:
    frmSearch - Main form
    qrySearchsubform - subform

    Queries:
    qrySearch - query

    Here is the code:

    Private Sub SearchButton_Click()


    Me.qrySearchsubform.Requery
    End Sub

    Private Sub ClearButton_Click()
    Dim Ctl As Control
    On Error Resume Next
    For Each Ctl In Me.Controls
    Ctl.Value = Null
    Next Ctl
    End Sub
    Attached Files Attached Files

  2. #2
    Vetgeorge is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Florida
    Posts
    29

    I think I found a solution

    I think I have it figured out:
    I made this change (in red):

    Private Sub SearchButton_Click()
    Me.qrySearchsubform.Requery
    End Sub

    Private Sub ClearButton_Click()
    Dim Ctl As Control
    On Error Resume Next
    For Each Ctl In Me.Controls
    Ctl.Value = Null
    Me.qrySearchsubform.Requery
    Next Ctl
    End Sub

    Now my subform (query) resets itself. But, I am sure I have extra lines in this code that are unnecessary, what can I remove? I am an amateur with vb codes and I cobbled it together from reading different posts and looking at examples, forgive me please

  3. #3
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    See if this link offers some insight: http://access.mvps.org/access/forms/frm0031.htm

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

Similar Threads

  1. Replies: 2
    Last Post: 03-12-2014, 01:31 AM
  2. Search Button in a Form not Working
    By spideynok in forum Forms
    Replies: 30
    Last Post: 03-29-2012, 01:10 AM
  3. How to clear a search form ?
    By Trojnfn in forum Access
    Replies: 2
    Last Post: 10-05-2011, 01:12 PM
  4. Replies: 2
    Last Post: 06-14-2010, 09:38 PM
  5. Search and Clear button
    By polk383 in forum Programming
    Replies: 1
    Last Post: 08-30-2006, 08:51 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