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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set Query Criteria via VBA

Status
Not open for further replies.

njellis

IS-IT--Management
Jul 17, 2006
29
I have a query (qryHTMLOutput) that I need to pre-set a criteria on a single item (Phone1). I have a button and when I click that button, I want it to set the criteria based on what's on the form (i.e. me.phone1)

I can't seem to figure out how to do this.

I have tried this: but I think it only works on "action queries"

Code:
Private Sub testEvent_Click()

 Dim dbs As DAO.Database
    Dim qdf As DAO.QueryDef

    Set dbs = CurrentDb
    Set qdf = dbs.QueryDefs("qryHTMLOutput")

    'Set the value of the QueryDef's parameter
    qdf.Parameters("Phone1").Value = Me.Phone1
    

    'Execute the query
    qdf.Execute dbFailOnError

    'Clean up
    qdf.Close
    Set qdf = Nothing
    Set dbs = Nothing
    
End Sub
 
Awesome worked great. Thank you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top