• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 398
  • Last Modified:

Form and Subforms


I have a form with two subforms:
Subform A= a query that matches expense records from Quickbooks to a more general category.  This is a datasheet form
Subform B= a form on the original table for the expense records; this is a regular form, one record at a time

I have two separate ones because I want the users to see the general category name, but also to be able to edit the records in the original table (I've added a field where they an assign an account)

My question is:
Once I've got the two subforms on a form, how do I link them so that scrolling through the datasheet pulls up the same record on the other subform, where they can add notes and assign an account?  They share the field "txnlineID"
0
BBlu
Asked:
BBlu
  • 2
2 Solutions
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
You can do something like this in the "first" subform:

Dim rst As DAO.Recordset

Set rst = Me.Parent.NameOfYourSecondSubformCONTROL.Form.RecordsetClone

rst.FindFirst "txnLineID='" & Me.txnLineID & "'"
If Not rst.NoMatch Then Me.Parent.NameOfYourSecondSubformCONTROL.Form.Bookmark = rst.Bookmark

This would be done in the Current event of your first subform.

I seem to recall being able to do something like this use an unbound Textbox on the Mainform, and setting the value of that Textbox in the first subform. Seems that you used that Textbox as one of the Link fields for the second subform (or may have been the ONLY link field, can't recall), but I'm just not sure.
0
 
BBluAuthor Commented:
I'm getting an error: Run-time error '2465';
Application-defined or object-defined error

It stops on the:
Set rst = Me.Parent.NameOfYourSecondSubformCONTROL.Form.RecordsetClone
line (see attached) error line
0
 
BBluAuthor Commented:
Is anyone available to help with this problem?
0
 
Boyd (HiTechCoach) Trimmell, Microsoft Access MVPCommented:
It sounds like what you need is what I call cascading sub forms.

The simplest method I know uses no VBA code. That's right no code.  Place a hidden text box on the main/parent form that has a control source that references a control on the first sub form that has the primary key value used to identify the record to show in the second sub form. The second sub form uses the text box as the master linking field.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now