How to the determine the current subform using a macro

  • Thread starter Pasadena-D via AccessMonster.com
  • Start date
P

Pasadena-D via AccessMonster.com

Hello,

I have a frmTaskList form that contains 3 subforms using tab controls. Each
tab has the following subforms:

SubForm Name: Form Name:
Task List Subform frmTask_List_Active_SubForm
Active Task OverDue frmTask_List_Active_OverDue_SubForm
New Task frmTask_List_Active_New_SubForm

On the frmTaskList I have a button that opens a frmEdit form. When frmEdit
opens I want it to contain the records of the one that was selected when the
user hit the button to open the frmEdit. The issue is that there are 3
subforms, and I don't know how to write the code to determin which subform it
came from. I have built code for each subform, and it works great, but I have
to have 3 buttons. I'd rather have just one button that does the job.

Here's the code that I use for each subform to make this work:
Task List Subform I use:
Private Sub cmdEdit_Click()

DoCmd.OpenForm "frmEdit", acNormal, "", "[Task_ID]=[Forms]![frmTask_List]!
[Task List Subform].[Form]![Task_ID]", , acNormal


End Sub

Active Task OverDue I use:
Private Sub cmdEdit_Click()

DoCmd.OpenForm "frmEdit", acNormal, "", "[Task_ID]=[Forms]![frmTask_List]!
[Active Task OverDue].[Form]![Task_ID]", , acNormal


End Sub

New Task I use:
Private Sub cmdEdit_Click()

DoCmd.OpenForm "frmEdit", acNormal, "", "[Task_ID]=[Forms]![frmTask_List]!
[New Task].[Form]![Task_ID]", , acNormal


End Sub

As you can see the code is exactly the same except the SubForm name changes
depending on which subform your on. Again, I'd like to have just one button
that does this form me, not 3 like I have now. Thanks in advance for your
help!
 
S

Steve Schapel

Pasadena,

This is VBA procedure you are talking about here, which in Access has
nothing to do with macros.

But anyway, since you're here... :)

I don't think you can do this directly. Because you see as soon as you
click the button on the main form, that's where the focus goes, it is no
longer on any of the subforms.

You could refer in your code to the Page property of the Tab Control, which
assumes that the subform you want the code to be based on is always the one
on the active Tab.

Alternatively, you could set a form level variable in the frmTaskList form,
the value of which you toggle on the Enter event of the subforms. And then
you could use this in the code on your command button.

But if it was mine, I think I would stick to the 3 button idea. But instead
of putting the buttons on the main form, I would put them on the Header
section of the subforms. Or else on the tab page alongside the subform. So
you only ever see one of tham at any given time.
 

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