Setting Query Parameter based on Form Entry

E

Eric

I have a command button on a Form that runs a query. It
appears on every record in the Form. I want the "part
number" field in the query to be filtered based on the
information in the "part number" field of the form record
that is active (on screen) when the user presses the
button.

This is the VBA that I have so far (what I need to know
is, what do I use in place of the ??????):

Private Sub RunQuery_Click()
On Error GoTo Err_RunQuery_Click

Dim stDocName As String

stDocName = "Received"
DoCmd.OpenQuery stDocName, acNormal, acEdit
DoCmd.ApplyFilter , "[PDC Part Number] = ??????"

Exit_RunQuery_Click:
Exit Sub

Err_RunQuery_Click:
MsgBox Err.Description
Resume Exit_RunQuery_Click

End Sub
 
T

Tom Ellison

Dear Eric:

What you put there is a reference to the value of the control. In a
continuous form, that will automatically follow the selected row.

This value can be simply:

Me.ControlName

Where ControlName is the name of the control containing the value in
question.

The phrase would read:

DoCmd.ApplyFilter , "[PDC Part Number] = " & Me.ControlName

Again substituting your control's name.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top