Consulting

Results 1 to 6 of 6

Thread: Search Button Help

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Newbie
    Joined
    Jun 2014
    Posts
    3
    Location

    Search Button Help

    Hi everyone,

    I'm new to MS Access and especially to VBA code. I'm trying to have my search button in a form find contact information based on what I type in the text boxes. However, my code (that a friend tried helping me with) keeps giving me a compile error when I try and run it. Is there something that looks wrong? Any help would be much appreciated.

    Edit - Seems like my requery line is giving the compile error.

    Option Compare Database
    Private Sub cmdSearch_Click()
        'Holds the Filtered Query
        Dim DataSource As String
        'Set Query based on text fields
        DataSource = "SELECT * FROM tMediaContacts WHERE " & _
                     "[Publication]          like '*" & Me.txtPublication & "*' AND" & _
                     "[Publication_Location] like '*" & Me.txtLocation & "*' AND " & _
                     "[Category_type]        like '*" & Me.txtCategory & "*' AND " & _
                     "[First_Name]           like '*" & Me.txtFirst & "*' AND " & _
                     "[Last_Name]            like '*" & Me.txtLast & "*' AND " & _
                     "[Email]                like '*" & Me.txtEmail & "*' AND " & _
                     "[Title]                like '*" & Me.txtTitle & "*' AND " & _
                     "[City]                 like '*" & Me.txtCity & "*' AND " & _
                     "[State]                like '*" & Me.txtState & "*'"
        'Set Form Record Source to be the Query
        Me.tMediaContacts_subform.Form.RecordSource = DataSource
        'Bind that query to the form
        Me.tMediaContacts_subform.Requery()
        Exit Sub
    End Sub
    
    
    Private Sub cmdClear_Click()
        'Clear all Text Boxes
        txtPublication = txtLocation = txtCategory = txtFirst = txtLast = txtEmail = txtTitle = txtCity = txtState = ""
        'Set the Record Source to be all records
        Me.tMediaContacts_subform.Form.RecordSource = "SELECT * FROM tMediaContacts "
        'Bind datasource to subform
        Me.tMediaContacts_subform.Requery()
        'Set the focus
        txtPublication.SetFocus()
    End Sub
    Last edited by Ebweaver; 06-11-2014 at 10:54 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
  •