Help Linking Subform and Form

R

rumichelle355

Below is a sample of my coding in my program. What happens is when I make a
selection in a field in my subform..it opens a form that reveals only the
information needed for that particular selection. What I'm finding is that
when the information is entered, it does not necessarily show up on the
correct line in the table...meaning they are not linked properly. Is there a
way to link the two somewhere in this particular coding?

If Me![Unit Classification] = "BTG Steam Boiler" Then
DoCmd.Close acForm, "FireLocs Form"
DoCmd.OpenForm "Form BTG Steam Boiler", acNormal, , , acFormEdit,
acDialog"
Else
If Me![Unit Classification] = "BTG Steam Turbine" Then
DoCmd.Close acForm, "FireLocs Form"
DoCmd.OpenForm "Form BTG Steam Turbine", acNormal, , , acFormEdit,
acDialog
 
T

Tom van Stiphout

On Tue, 10 Nov 2009 19:31:18 -0800, rumichelle355

You lost me.
DoCmd.OpenForm opens a form. Whether there are subforms on that form
is irrelevant and cannot be controlled by this command.
Subforms are linked to their parent forms via two properties of the
subform control: LinkMasterFields and LinkChildFields.

Perhaps you mean: when I open Form2, I want it to reflect the record
selected on Form1. If so, this is a FAQ and you should have no problem
finding information online.

-Tom.
Microsoft Access MVP
 
J

John W. Vinson

Below is a sample of my coding in my program. What happens is when I make a
selection in a field in my subform..it opens a form that reveals only the
information needed for that particular selection. What I'm finding is that
when the information is entered, it does not necessarily show up on the
correct line in the table...meaning they are not linked properly. Is there a
way to link the two somewhere in this particular coding?

If Me![Unit Classification] = "BTG Steam Boiler" Then
DoCmd.Close acForm, "FireLocs Form"
DoCmd.OpenForm "Form BTG Steam Boiler", acNormal, , , acFormEdit,
acDialog"
Else
If Me![Unit Classification] = "BTG Steam Turbine" Then
DoCmd.Close acForm, "FireLocs Form"
DoCmd.OpenForm "Form BTG Steam Turbine", acNormal, , , acFormEdit,
acDialog

These are NOT SUBFORMS.

A Subform exists in a Subform control on the mainform. You don't close the
mainform, you don't open the subform.

If you want to keep data in the [FireLocs Form] form's recordsouce in synch
with records in the [BTG Steam Boiler] form's recordsource, it would be much
easier if you had a Subform control on [FireLocs Form] and dynamically set its
SourceObject proprety to whichever form is needed.

Failing that, you'll need at least three bits of code - you'll need to include
a WhereCondition argument in your OpenForm event (to specify which record or
records should be displayed); you'll need to pass some ID (whatever field
defines the linkage, you haven't said) in the OpenArgs argument; and you'll
need code in the Open event of the Form BTG Steam Boiler or other form to
check for a value in OpenArgs and make some use of it (perhaps setting a
DefaultValue property on some control). It can be done, but the specifics will
depend on the structure of your tables, their relationships, and the details
of the linkage.

A true Subform manages all this for you with no code at all. Take your pick!
 

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

Top