Passing a Variable from a form to a querry "criteria"

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

Guest

I have a VBA error routine embedded in a Form that if triggered opens a
second form whose record source is a querry. In the original form, I have an
ID number which I want to use as a "criteria" for the ID field in the
querry. Can I take the variable holding the ID number in the original form,
and pass it to the new form, which in turn would selectively open the querry
with this as the criteria for the ID field?
So the code in frmOriginal is:

vID=3
DoCmd.OpenForm "frmTestPassthrough", acPreview, , , , acDialog
and then I am lost.

The reason I use the acDialog is because I will come back to the original
form after manipulating the data in the newly opened form.

As always, I appreciate the help of this group forum.
Gene
 
Hi Gene

You do this through WhereCondition, which is the 4th argument for OpenForm.

Construct a string which is the WHERE clause for a SQL statement, but
without the "WHERE". For example:

Dim sWhere as String
sWhere = "[some field in your recordsource query]=3"

or

sWhere = "MyIdField=" & Me![SomeTextbox]

Then you pass that string to OpenForm:

DoCmd.OpenForm "frmTestPassthrough", acPreview, , sWhere, , acDialog

It will automatically apply a filter to the form as it is opened so that
only those records matching the given criteria are displayed.
 
Back
Top