Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parent form 2

Status
Not open for further replies.

JesOakley

Programmer
Jan 21, 2008
42
GB
I have a form which is potentially called from a number of different forms. I want to close the form automatically when the calling form closes, but not when one of the other potential forms closes. How can I tell which was the real parent?
 
You could pass the calling form name as an OpenArg.
 
How are ya JesOakley . . .

Try this:
In the declaration section of a module in the modules window, copy/paste the following line, which sets up a global variable to hold the 1st calling form:
Code:
[blue]Public FirstCaller As String[/blue]
In the same module, copy/paste the following routine:
Code:
[blue]Public Sub CommonFrmCtl(frmName As String)
   
   If FirstCaller = "" Then
      DoCmd.OpenForm "[purple][B][I]CommonFormName[/I][/B][/purple]"
   ElseIf frmName = FirstCaller Then
      firtscaller = ""
      DoCmd.Close acForm, "[purple][B][I]CommonFormName[/I][/B][/purple]", acSaveYes
   End If
   
End Sub[/blue]
[purple]If you use a new module, don't give the module the same name as the routine![/purple]

From each calling form, open the common form with:
Code:
[blue]Call CommonFrmCtl(Me.Name)[/blue]
Name above is the forms Name property, so don't change it!

From each calling form, in the forms [blue]On Close[/blue] event, make the same call to close the common form:
Code:
[blue]Call CommonFrmCtl(Me.Name)[/blue]

The 1st calling form opens the common form, thereafter, only the 1st calling form can close the common form.

[blue]Your Thoughts? . . .[/blue]


Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Thanks for all the ideas. I was rather hoping that me.parent was going to be the answer, but I couldn't quite get my head around it.
Aceman; your solution is sort of what i was heading towards, and trying to avoid because i just felt Access forms should just know what invoked them.
Danvlas; I guess if i wanted to make the process flexible, I could use your suggestion with Remou's and pass the activeform as the openarg.
However, i'm a lazy, short-sighted sod, and i think i'll just hardcode the form name into the open.
Thank you all for your inputs. Really nice to have people answering so promptly with a good range of answers that allow you to pick the one that fits best. Cheers guys :)
 
JesOakley . . .

I see I forgot an all important line of code. The line is in [purple]purple[/purple]:
Code:
[blue]Public Sub CommonFrmCtl(frmName As String)
   
   If FirstCaller = "" Then
      [purple][b]FirstCaller = frmName[/b][/purple]
      DoCmd.OpenForm "CommonFormName"
   ElseIf frmName = FirstCaller Then
      FirtsCaller = ""
      DoCmd.Close acForm, "CommonFormName", acSaveYes
   End If
   
End Sub[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top