Macro on SubForm won't Work

  • Thread starter Thread starter Will
  • Start date Start date
W

Will

This is a little complicated but hopefully I have laid out the issues and
the question clearly and someone will give me some advice...

I have...

Company_Table
... idCompany
... Company
... Department

People_Table
... idPerson
... idCompany
... Name

Query_All - (using both tables with all fields from each table)

Query_Company - (using both tables - selected fields from the tables as
below)
... idCompany (from Company_Table)
... Company (from Company_Table)
... Department (from Company_Table)
... idPerson (from People_Table)

I made a Form on from Query_Company with all fields included ---
frm_Query_Company

I made a Form on Query_All with all fields included --- frm_Query_All

I created a double click macro for the Company field in frm_Query_Company...
the macro opens the associated frm_Query_All record so you can see all
fields in the record... and it works!

I then made frm_Query_Company a sub-Form in frm_Query_All so when looking at
any record I can see any other records in the db for the same company.

But when I double click on the Company Field in the sub-Form it doesn't work
right... it ask me for the id of the frm_Query_All record... when I
manually enter that it opens the correct record OK

How can I fix this to open record automatically when I double click on it as
a sub-Form?

My Macro code for the Company field of frm_Query_Company is...
[idPerson]=[Forms]![frm_Query_Company]![idPerson]

thanks for any help.
 
I got it to work... for others who may be interested...

Don't build the macro on the Form that will be the Sub_Form before you make
it a Sub_Form.

First make it a Sub_Form then build build the macro by switching the Parent
Form to Design view... go down to the field in the sub_form and then create
the double click event macro...... so code references the parrent form and
the sub form... like this...

[idPerson]=[Forms]![frm_Query_People]![frm_Query_Company]![idPerson]

Note that the string on the right side of the equal mark first references
the parent form... then the sub form and then the field in the sub form on
which the double click macro is built.

The string on the left of the equal mark references the relative field in
the form the macro is to open... that form is identified in the Form Name
field of the Macro.

So the Macro says to OpenForm frm_query_Company where the field idPerson is
the same as the field idPerson that is double clicked in the sub form
frm_Query_Company that is in the main form frm_Query_People.

Confusing to try and explain but simple once you get it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top