Results 1 to 10 of 10
  1. #1
    4 Star Lounger
    Join Date
    Feb 2006
    Posts
    504
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Search Engine (2003)

    hi,

    I am trying to do a search menu. In the main menu have some input filed for users to enter, and after user click search the subform with search result will appears. If users click "clear" button, the subform will disappear.

    How can I do it?

    Thanks

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

    Re: Search Engine (2003)

    Create a query based on the relevant table.
    You can refer to the search control (text box, combo box, list box) in the criteria of the query, for example

    [Forms]![frmMenu]![txtSearch]

    or

    Like [Forms]![frmMenu]![txtSearch] & "*"

    where frmMenu is the name of your menu form and txtSearch the name of the search text box. Replace these with the appropriate names. Set the Record Source of the subform to the name of this query.

    Create On Click event procedures for the Search and Clear command buttons:

    Private Sub cmdClear_Click()
    Me.txtSearch = Null
    Me.sbfSomething.Visible = False
    End Sub

    Private Sub cmdSearch_Click()
    If IsNull(Me.txtSearch) Then
    MsgBox "Please enter something to search for.", vbExclamation
    Me.txtSearch.SetFocus
    Else
    Me.sbfSomething.Form.Requery
    Me.sbfSomething.Visible = True
    End If
    End Sub

  3. #3
    4 Star Lounger
    Join Date
    Feb 2006
    Posts
    504
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Search Engine (2003)

    Hi

    Thanks a lot.

    I did try the code, but when I click "search" button the following message pops up "Cmplie error: Method or data member not found."
    As I open main menu, the subform also appear with blank. I would like subform disappear unless I click " Search button".

    Thanks

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

    Re: Search Engine (2003)

    The error message means that the name that is highlighted when you click Debug is incorrect. You should replace all names in the code I posted with the names in your database.

    To hide the subform initially, set the Visible property of the subform as a control on the main form to No in design view.

  5. #5
    4 Star Lounger
    Join Date
    Feb 2006
    Posts
    504
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Search Engine (2003)

    Thanks.

    What's "sbfSomething?" Should I keep "sbf" or replace my form with everything? Below is my corrent code:

    Private Sub Clear_Click()
    Me.txtSearch = Null
    Me.sbfSomething.Visible = False

    End Sub

    Private Sub Search_Click()
    If IsNull(Me.MRN) Then
    MsgBox "Please enter something to search for.", vbExclamation
    Me.MRN.SetFocus
    Else
    Me.Search.Form.Requery
    Me.Search.Visible = True
    End If

    End Sub

    Please help me state out errors, thanks!

    Regards!

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

    Re: Search Engine (2003)

    If your search text box is named MRN, you should replace txtSearch in the first procedure with MRN too.

    sbfSomething should be replaced with the name of the subform as a control on the main form. This is not necessarily the same as the name of the subform in the database window. To find the control name, open the main form in design view and click *once* on the subform. Its name will be displayed in the title bar of the Properties window. You should replace Search in the lines

    Me.Search.Form.Requery
    Me.Search.Visible = True

    with the same name. (You shouldn't use Search there, because that is already the name of the command button)

  7. #7
    4 Star Lounger
    Join Date
    Feb 2006
    Posts
    504
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Search Engine (2003)

    hi,


    I really can't find the "visible property" of the subform? Can you tell me more detail about it?


    Please see below screen shot:

    Thanks

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

    Re: Search Engine (2003)

    You're looking in the wrong place. Visible is not a property of the subform by itself, but of the subform as a control on the main form.
    Close the subform.
    Open the main form in design view.
    Click *once* on the subform. Don't click a second time, for that would select something in the subform.
    If you click twice by accident, click outside the subform, then click *once* on the subform.
    The Visible property will be the first property in the Format tab of the Properties window.

  9. #9
    4 Star Lounger
    Join Date
    Feb 2006
    Posts
    504
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Search Engine (2003)

    Thank you so much.

    I am able to dispear subform when I click "clear" button. But subform is appear when I open the form, how can I solve it? Also even subform disappear but the space still stay. Is any way to disapper the extra space at the same time?

    Thanks.

    Regards

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

    Re: Search Engine (2003)

    > But subform is appear when I open the form, how can I solve it?

    See previous replies.

    I wouldn't bother with growing and shrinking the form.

Posting Permissions

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