Results 1 to 6 of 6
  1. #1
    2 Star Lounger
    Join Date
    Mar 2002
    Posts
    164
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Access Forms (2003)

    I have a search form in which a users enters a value to pull up specific criteria...

    Private Sub Search_Bttn_Click()
    On Error GoTo ErrHandler

    Me.Visible = False
    DoCmd.OpenForm "Edit - Purchase Orders", acViewNormal, acEdit
    DoCmd.Close acForm, "Search - Purchase Orders"

    ExitHandler:
    Exit Sub

    ErrHandler:
    If Err = 2501 Then
    ' Action canceled - ignore
    Else
    ' Display error message
    MsgBox Err.Description, vbExclamation
    End If
    Resume ExitHandler
    End Sub

    If a record is found it closes the form and displays the found record in the second form. If a record is not found, it closes the search form and returns a message. But when I search again, the previous text is still in the search box. Is it possible to clear this out?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Access Forms (2003)

    What is the name of the search form? Is it "Search - Purchase Orders"?
    Is the search box bound to a field, i.e. does the Control Source property of the search box contain a field name?

  3. #3
    2 Star Lounger
    Join Date
    Mar 2002
    Posts
    164
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Access Forms (2003)

    Correct, "Search - Purchase Orders" is the name of the search form. Additionally, the search box is not bound to a field.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Access Forms (2003)

    Does it help if you move the line

    DoCmd.Close acForm, "Search - Purchase Orders"

    down to between the ExitHandler: label and the line Exit Sub?

  5. #5
    2 Star Lounger
    Join Date
    Mar 2002
    Posts
    164
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Access Forms (2003)

    Excellent. Thanks a million!

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Access Forms (2003)

    Explanation (mainly for others reading this thread): if opening the form in the line

    DoCmd.OpenForm ...

    gets canceled, error 2501 occurs, and the code jumps from DoCmd.OpenForm to the error handling section, skipping DoCmd.Close in its original position. So the search form was only hidden, not really closed. Next time it was actually only unhidden instead of opened from scratch, so the search box still contained the old search text. Moving the DoCmd.Close line to the exit handler section ensures that it is *always* executed.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •