Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing parameter to query from VBA 1

Status
Not open for further replies.

ImChard

IS-IT--Management
Jun 17, 2011
6
US
I have a form that opens and displays records based on a select query. I want to add a button to the form so thet when clicked there is a prompt comes up that aske for the [Last_Name]to filter the records on and then refresh the form to reflect this.. I can do this in the criteria of the query (Like "*" & [Enter all or part of Last Name] & "*") but then it happens anytime the query is run. I only want it to run when the button is clicked.
 
How are ya ImChard . . .

Try the following in the [blue]On Click[/blue] event of the button:
Code:
[blue]   Dim Ans As String, DL As String
   
   DL = vbNewLine & vbNewLine
   
   Ans = InputBox("Enter LastName below to filter or" & DL & _
                  "Click Close or Cancel to remove filter.", _
                  "Filter By LastName")
   
   If Ans <> "" Then
      Me.FilterOn = False
      Me.Filter = "[Name] Like '*" & Ans & "*'"
      Me.FilterOn = True
   Else
      Me.FilterOn = False
   End If[/blue]
[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top