There's sample code to do this in Access Developer's xx Handbook by Litwin,
Getz and Gilbert et al (where xx is whatever's appropriate for the version
of Access you're using). You can learn more about their books at http://www.developershandbook.com/