Barbara:
The argument name is 'WhereCondition'. Its an argument of the OpenForm
method, whose syntax is:
DoCmd.OpenForm(FormName, View, FilterName, WhereCondition, DataMode,
WindowMode, OpenArgs)
The list in parentheses is a list of arguments. All bar the FormName
argument are optional. The argument name can be omitted, but then you have
to put a series of commas in so its in the right place in the list. Or you
can name the argument, following it with := and then the expression. What
I'd done in my first post was omit the name, but not put in the necessary
commas. In my correction I added the name, so the commas aren't necessary.
Assuming you've created a form based on your main 'people' table and another
based on your related table, to open the latter from the former you'd add a
button to the former, and then put the line of code in its Click event
procedure. I'm not using Access 2007, but in earlier versions this is how
its been done the same way since before Doris Day was a virgin, so hopefully
it hasn't changed:
1. With the main form open in design view select the button, and make sure
its properties sheet is open.
2. Select the On Click event property on the Events tab of the properties
sheet.
3. Select the 'build' button; that's the one on the right with an ellipsis
(3 dots) on it.
4. In the dialogue which opens select Code Builder and click OK.
5. The VBA window will now open at the button's Click event procedure.
You'll see two lines already in place. Enter the line of code as a new line
between the two, changing YourOtherForm to the actual name of the form to be
opened , and MyID to the actual name of the primary/foreign key fields which
link the tables on which the forms are based. If the MyID fields are number
data type use:
DoCmd.OpenForm "YourOtherForm", WhereCondition:="MyID = " & MyID
If text data type use:
DoCmd.OpenForm "YourOtherForm", WhereCondition:="MyID = """ & MyID & """"
The latter wraps the value of MYID in quotes characters. When including a
quotes character in a string expression, a pair of contiguous quotes is used;
this is interpreted as a literal quotes character.
6. Save the form, switch to normal form view and click the button. If
all's well, the other form should open, filtered to just those records which
relate to the current record in the main form.
BTW when I was young my nickname was Kiwi, which puzzled people because I
don't have any New Zealand connections; I'm Irish. But my initials are KWS,
and at school I had these on my bag. Someone inserted two Is so it read
KIWIS, and from then on I was known as Kiwi.
Ken Sheridan
Stafford, England