Friday, July 11, 2008

Using OpenArgs to pass one or more parameters to a form when it opens

When you use DoCmd.OpenForm to launch a form, there are a number of parameters that you can use. At the end of the parameter string is OpenArgs, which doesn’t get as much use as it deserves. Basically, OpenArgs lets you pass a string or number to the opening form, which can then respond to that value in a number of ways. For example, you could:
  • Send a single value which populates a predefined field (for example, the ID field)
  • By building a string separated by pipe symbols, you can define field name | data pairs and parse that data when the form opens. In this way you can populate one or more fields with data from the caller form.
  • Use a SQL string to filter a popup form, displaying specific data
  • Another cool thing: OpenArgs works with reports too, so you can easily customise report filters on the fly.
To find out more, go here and also follow the link at the bottom of that page for an example that uses SQL to simplify many-to-many data entry.

Denis Wright

1 comment:

Garry Robinson said...

Well done Denis on your first post. There is a slightly different way to accomplish this mentioned in a forthcoming article of mine.
http://www.databasejournal.com/features/msaccess/article.php/3758776

Garry