Button runs parameter query

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can i have a button that runs a parameter query, where the parameter data is
pulled from the current data on the form.

currently i click the button on the form and enter the parameter value which
is on the form im working in.
(new user)
 
Hi, Joe.

Open your query in Design View. In the column where the field is listed,
place the following in the "Criteria:" section:

[Forms]![MyForm]![txtFieldName]

.. . . and replace MyForm with the name of your form that _must_ be open
whenever this query runs, and replace txtFieldName with the name of the text
box that contains the value you'd like to use as the query's parameter. Save
the query.

With the form open, open the query in Datasheet View (you may use your
form's button for this) and the records will be "filtered" on the criteria
selected in the form's text box.

In the form's button's OnClick( ) event, try:

Private Sub OpenQryBtn_Enter()

On Error GoTo ErrHandler

DoCmd.OpenQuery "qryGetFormCriteria"

Exit Sub

ErrHandler:

MsgBox "Error in OpenQryBtn_Enter( ) in" & _
vbCrLf & Me.Name & _
" form." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & Err.Description
Err.Clear

End Sub

.. . . where OpenQryBtn is the name of the button and qryGetFormCriteria is
the name of the query.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.
 
Back
Top