Opening subforms relating to the information on the main form

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

Guest

I am designing a database that shows visits by an accountant to a firm to
carry out an audit. On the form I have a button which when clicked opens a
sub form so that any breaches by a firm can be entered onto this sub form.
At the moment I have forms, one called "Firms" and the other "Breaches". I
would like to keep the two seperate for reporting purposes, however, when the
button in the main form is clicked I would like the correct subform to open
up depending on the firm ID in the main form.

Can this be done?
 
Qudeer said:
I am designing a database that shows visits by an accountant to a
firm to carry out an audit. On the form I have a button which when
clicked opens a sub form so that any breaches by a firm can be
entered onto this sub form. At the moment I have forms, one called
"Firms" and the other "Breaches". I would like to keep the two
seperate for reporting purposes, however, when the button in the main
form is clicked I would like the correct subform to open up depending
on the firm ID in the main form.

Can this be done?

First let's get the terminology correct. What you are describing are not
"subforms". A subform is a form that is displayed embedded within another using
a subform control. What you are describing is simply the act of opening a form
with a fiter criteria that is derived from a value in another form. Some
describe these as "linked forms", but even that might be an overstatement.

Now as to your question I am not clear what your setup is from your description.
You describe a "main form" and forms named "Firms" and "Breaches". Is "Firms"
also the "main form" or do you have one main form and two possible "linked"
forms that you want to open?

The act of opening one form showing data related to the record in the current
form is a common approach and is even offered as one of the wizard options when
you drop a new command button onto a form. I would try that and then examine
the code behind the resulting button. Essentially it uses the optional WHERE
argument of the OpenForm method to filter the form being opened so that the
linking field matches that of the current record. If these linking fields were
named "ID" it would look something like...

DoCmd.OpenForm "FormName",,,"ID = " & Me!ID
 
There are two forms called firms and breaches. When looking at firms, I can
click a button on that form and open another form called breaches. I would
like the information on the breaches form to relate to the firm.

I'm not an IT person thats why the description of my problem is in plain
english - sorry.
 
Qudeer said:
There are two forms called firms and breaches. When looking at
firms, I can click a button on that form and open another form called
breaches. I would like the information on the breaches form to
relate to the firm.

I'm not an IT person thats why the description of my problem is in
plain english - sorry.

As I stated...drop a new command button on the form "firms" with the Toolbox
wizard enabled. One of the choices offered by the wizard does exactly what you
need.
 
Back
Top