Results 1 to 14 of 14
  1. #1
    pbouk is offline Advanced Beginner
    Windows Vista Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    58

    Clearing a search box on a form

    Hi there,
    This is simple I'm sure, but I can't find a clear answer on the web, so thanks in advance for your help.

    I have two search boxes that search company names and last names from two tables, and pulls up a form record. So basically the user can search for either company name or last name, whichever they prefer, in order to locate the form with the associated information for that contact.

    I want the search box to go blank once it populates the form with the contact data. eg, user searches for Jane Bryant, and selects the name, brings up the record. Search box should then automatically go blank, ready for a new search.

    Is this an afterupdate thing? Or do i set the default to null? I've tried a few different codes I've found but nothing seems to work.

    thanks.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Either

    Me.TextboxName = Null
    Me.TextboxName = ""
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    How do you initiate the search? A button? As the last line before "End Sub", you could try adding:

    (these should be unbound)
    Me.Search_Box_1 = NULL
    Me.Search_Box_2 = NULL

    Replace "Search_Box_x" with your text box names.

  4. #4
    pbouk is offline Advanced Beginner
    Windows Vista Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    58
    Actually, it's based on a query. Does this still apply?
    I tried it and it didn't work...

  5. #5
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Aren't the search text boxes unbound??

  6. #6
    pbouk is offline Advanced Beginner
    Windows Vista Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    58
    Yes, they are. Here is my code for one of the text boxes. I might have it all wrong, so forgive me. I'm assuming I am adding this code to the afterupdate event:

    '------------------------------------------------------------
    ' SearchCompany_AfterUpdate
    '
    '------------------------------------------------------------
    Private Sub SearchCompany_AfterUpdate()
    On Error GoTo SearchCompany_AfterUpdate_Err

    ' _AXL:<?xml version="1.0" encoding="UTF-16" standalone="no"?>
    ' <UserInterfaceMacro For="SearchCompany" xmlns="http://schemas.microsoft.com/office/accessservices/2009/11/application" xmlns:a="http://schemas.microsoft.com/office/accessservices/2009/11/forms"><St
    ' _AXL:atements><Action Name="SearchForRecord"><Argument Name="WhereCondition">="[ContactID] = "&amp; Str(Nz([Screen].[ActiveControl], 0))</Argument></Action></Statements></UserInterfaceMacro>
    DoCmd.SearchForRecord , "", acFirst, "[ContactID] = " & Str(Nz(Screen.ActiveControl, 0))


    SearchCompany_AfterUpdate_Exit:
    Exit Sub

    SearchCompany_AfterUpdate_Err:
    MsgBox Error$
    Resume SearchCompany_AfterUpdate_Exit

    Me.SearchCompany = Null
    End Sub

  7. #7
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    If the control "SearchCompany" (a text box) is bound, it means that the control is connected to a field in the underlying query/table.
    Lets say the control "SearchCompany" is currently displaying "ABC Block, Co". If you then delete or change the name to "XYZ Industries", you have changed the company name for that record. Probably not what you want or expected.



    Here are two examples of search forms:

    http://allenbrowne.com/ser-62.html
    http://access.mvps.org/access/forms/frm0045.htm

  8. #8
    pbouk is offline Advanced Beginner
    Windows Vista Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    58
    well.....the search boxes ARE unbound. They say so in the design view.
    But yes, I can delete or change the name, and that's okay, as this is a contacts database and it needs to be editable. Does that make sense?

  9. #9
    pbouk is offline Advanced Beginner
    Windows Vista Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    58
    That is, the form is editable. Not the search box.... hope that makes sense!

  10. #10
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Would you post your dB or a picture of your search form?

    If the "SearchCompany" text box is unbound, then this code should have cleared the text box:

    Code:
    Me.SearchCompany = Null
    BTW, the code for the afterupdate event looks like it was scrambled.... Post #6

  11. #11
    pbouk is offline Advanced Beginner
    Windows Vista Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    58
    Thanks for your help. It's definitely unbound (there is no source), however that code still doesn't clear the search box. The search box works perfectly otherwise, so i think the scrambling happened with my cut and paste. I'd rather not post the database as it has confidential info.
    I guess I'll just have to keep searching.

  12. #12
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Set a breakpoint in the after update code, then step through it seeing where the error is.....

    You could make a copy pf the dB without data and add a couple of nonsense records. Do a compact and repair, then zip it....???

  13. #13
    pbouk is offline Advanced Beginner
    Windows Vista Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    58
    Hi there,
    Here is my code again, can you tell me where to put the code you suggest. I've tried everything!

    ' Combo202_AfterUpdate
    '
    '------------------------------------------------------------
    Private Sub Combo202_AfterUpdate()
    On Error GoTo Combo202_AfterUpdate_Err


    DoCmd.SearchForRecord , "", acFirst, "[ContactID] = " & Str(Nz(Screen.ActiveControl, 0))




    Combo202_AfterUpdate_Exit:
    Exit Sub


    Combo202_AfterUpdate_Err:
    MsgBox Error$
    Resume Combo202_AfterUpdate_Exit


    End Sub

  14. #14
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I am still kinda lost...
    Try this:

    Code:
    ' Combo202_AfterUpdate
    '
    '------------------------------------------------------------
    Private Sub Combo202_AfterUpdate()
    On Error GoTo Combo202_AfterUpdate_Err
    
    
    DoCmd.SearchForRecord , "", acFirst, "[ContactID] = " & Str(Nz(Screen.ActiveControl, 0))
    
    Me.SearchCompany = Null
    
    
    Combo202_AfterUpdate_Exit:
    Exit Sub
    
    
    Combo202_AfterUpdate_Err:
    MsgBox Error$
    Resume Combo202_AfterUpdate_Exit
    
    
    End Sub
    Change "SearchCompany" to your text box name.

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

Similar Threads

  1. Clearing a Form
    By dabatman in forum Forms
    Replies: 4
    Last Post: 01-20-2012, 11:51 AM
  2. Clearing a form - having real issues
    By mike_980 in forum Forms
    Replies: 9
    Last Post: 01-11-2012, 06:15 AM
  3. Clearing certain boxes on form for next record using VB
    By justinwright in forum Programming
    Replies: 3
    Last Post: 07-21-2010, 12:16 PM
  4. Error when clearing form
    By turbo910 in forum Forms
    Replies: 11
    Last Post: 11-26-2009, 11:03 AM
  5. clearing a form
    By macsterling in forum Forms
    Replies: 0
    Last Post: 07-31-2008, 10:38 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