Form/Subform Synchronization

G

Guest

I have two form/subforms. The main forms have command buttons that enable
the other form/subform. The subforms are identical with the exception of
three text boxes. The forms are exactly the same.

The main form has a list box that tells Access which record to retrieve.
The two subforms get out of sync when I use the command buttons to toggle
between the ‘expanded’ and ‘compressed’ views of information for each record.


The command buttons use an After Update event to load the form/subform
combinations.

How do I keep the subforms on the same record in the table?

This is an attempt to mimic the expand form functionality.

Thanks.
Acc2003
 
G

Guest

My mistake. The command buttons use the On Click event. The subforms have
the After Update event.
 
S

Stuart McCall

roccogrand said:
My mistake. The command buttons use the On Click event. The subforms
have
the After Update event.

You could try making the buttons call the Subform's AfterUpdate event(s) :

Change the AfterUpdate event procedure's scope from Private to Public.

Then, in The OnClick event procedure for the button, and assuming the button
is on your main form, type:

Me!SubFormControlName.Form!ControlName_Click

If the button is on the subform, place the following in the AfterUpdate
event procedure for the control:

ControlName_Click
 
G

Guest

If the forms are identical, why do you need two of them? Just change the
SourceObject of the subform control to the appropriate subforms name. This
assumes that the command button that "toggles between ... views". If you
have the Master/Child relationships setup correctly, this should work just
fine.

Private sub cmd_ChangeView_Click

Select Case me.sub_yourSub.sourceObject
Case ""
me.sub_yourSub.visible = false
Case "frm_expanded"
me.sub_yourSub.SourceObject = "frm_compressed"
Case "frm_Compressed"
me.sub_yourSub.SourceObject = "frm_Expanded"
Case else
msgbox "Invalid form as subform for sub_yourSub"
End Select

End Sub

Another way to address this would be to put two subform controls on the same
form (you might even want to consider putting them on a tab control). Hide
them both and set their source object to "" until they are needed. Then,
populate the SourceObject of each one (as it is needed) and make it visible.

HTH
Dale
me.sub_yourSub.SourceObject
 
G

Guest

Thanks both of you but I am still fiddling with this issue.

I think that I need to always compare the values in the ListBox (in the main
Form), in a Text Box in the main Form, and in the Subform when different
values are selected in the ListBox. If the value in the ListBox isn't set to
the same value in the Text Box and the in the SubForm, incorrect data is
shown in the SubForm.

I have some ideas but just don't have the enough knowledge about addressing
the values. Hopefully, I'll gain this over the weekend.

Have a nice weekend.

LDN
 

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