• Search Engine (2003)

    Author
    Topic
    #429956

    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

    Viewing 0 reply threads
    Author
    Replies
    • #1002630

      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

      • #1002632

        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

        • #1002635

          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.

          • #1002637

            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!

            • #1002640

              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)

          • #1002654

            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

            • #1002655

              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.

            • #1002664

              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

            • #1002676

              > 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.

    Viewing 0 reply threads
    Reply To: Search Engine (2003)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: