Requery subform according to current tab control

B

BruceM

I have a form with a tab control. The tab pages are sections of the main
form, placed on tabs for convenience. The main form has a subform I use for
linking to other files on the network. The main form and subform record
sources are related one-to-many.
When I create a subform record (which contains among other things the file
to which I am linking) I want it to contain information about the current
tab control when the record was created. The following code is in the Click
event of a command button on the subform. I have called the main form
frmMain, and the tab control tabMain. TabField is the field in the subform
record source in which the tab's caption is stored. The last two lines of
code don't really enter into this question, I don't think, but I left them
there just in case.

Dim lngIndex As Long ' PageIndex property
Dim strCaption As String ' Caption of the tab control

' The PageIndex property for the current tab control
lngIndex = Forms!frmMain.tabMain.Value
' The Caption for the current tab control
strCaption = Forms!frmMain.tabMain.Pages.Item(lngIndex).Caption
DoCmd.GoToRecord , , acNewRec
Me.TabField = strCaption
Me.txtLink.SetFocus
DoCmd.RunCommand acCmdInsertHyperlink

This all works as it should. The thing I'm trying to do now is to have the
subform's record source be filtered (or otherwise adjusted) for the current
tab page. If the tab page captions are "Start", "Middle", and "End", if I
am at the "Middle" tab when I run the code above, "Middle" is stored in
TabField. When I click on the "Middle" tab, I want to adjust the subform's
record source so that it shows only those records with "Middle" in the
TabField field.

Because of the relationship between the main form's record source and the
subform's record source, and the Link Parent and Link Child fields in the
subform control, at each main form record I see only the related subform
records, as I should. I'm trying to take it a step further and filter by
TabField as well.
 

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