Joe said:
Thanks for all the useful ideas. For posterity's sake, here is what I
did to get the desired result.
I created a new module ("UberModule") unattached to any forms and
added a public variable:
Public SSFRclassID As Integer
Nevermind the name... SSFR is just an abbreviation of the name of the
form that uses the variable. In the parent form that calls up my
student roster, I added this line to the "open linked form" action
code:
UberModule.SSFRclassID = [classID]
I found it was better to do this in the parent form than in the linked
form, because there doesn't seem to be any event that executes before
the first query (not even BeforeQuery). Next, in the UberModule, I
created a function that, when called, returns the variable:
Public Function SSFRkey()
SSFRkey = SSFRclassID
End Function
Finally I altered the SQL of my query to use "... WHERE
classID=SSFRkey() ...". I'm getting the right result every time.
That's logically correct (the slightly more roundabout way I
mentioned earlier). A subtle issue with that is that it can
make debugging more complex because any unhandled error in
any code will **reset** your code project (i.e. clear all
module level and static variables) so you need to be more
careful about initializing the global variables.
The way many people avoid that complication is to use a
hidden text box on an open form. Some people go so far as
to create a separate, always open, hidden form just to hold
the "global" values. I usually just use a hidden text box
You mean, if there's a textbox called [x] on my form,
I can use "WHERE id=[x]" in the SQL?
No, that is not quite correct. Because there might be a
text box named x on any number of open forms, you need to
specify the form that contains the x you want to use:
WHERE id=Forms!theform.x
I also note that you have missused the [ ] in a couple of
places. The brackets must be around a single name, not a
full reference, i.e. [Forms!theform.x] is wrong. Note that
the [ ] are not required when the name contains only
alphanumeric and underscore characters. OTOH, Access often
adds the brackets around every name, so you might see some
redundant brackets, e.g. [Forms]![theform].[x] even though
you did not put them there. The best advice I can give on
this issue is to only use names with alphanumeric
characters.