dbTalk Databases Forums  

Determine what the main form

comp.databases.ms-access comp.databases.ms-access


Discuss Determine what the main form in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
 
Posts: n/a

Default Determine what the main form - 04-02-2011 , 03:03 PM






I have a subform which I've always used in one main form. Now I would like
to use the same subform in another main form, only the subform then needs a
different record source and the behavior of the subform should at some
points be slightly different which I'm planning to do in VBA.

My questions are: how can I check in my subform by which mainform it is
opened? And secondly: can I safely use the subform in 2 mainforms at the
same time?

Thank you,
Martin

Reply With Quote
  #2  
Old   
Marshall Barton
 
Posts: n/a

Default Re: Determine what the main form - 04-02-2011 , 03:38 PM






<martin (AT) hotmail (DOT) com> wrote:

Quote:
I have a subform which I've always used in one main form. Now I would like
to use the same subform in another main form, only the subform then needs a
different record source and the behavior of the subform should at some
points be slightly different which I'm planning to do in VBA.

My questions are: how can I check in my subform by which mainform it is
opened? And secondly: can I safely use the subform in 2 mainforms at the
same time?

Sure you can do that. You can check the name of the main
form:

Select Case Parent.Name
Case "main form 1"
...
Case "main form 2"
...
Case Else
MsgBox "wrong main form or not a subform"
End Select

--
Marsh

Reply With Quote
  #3  
Old   
 
Posts: n/a

Default Re: Determine what the main form - 04-03-2011 , 03:36 AM



Thanks. Works well!

Martin

"Marshall Barton" schreef in bericht
news:e02fp6dn4e6kgtdhks53vco0glp6ue0s3q (AT) 4ax (DOT) com...

<martin (AT) hotmail (DOT) com> wrote:

Quote:
I have a subform which I've always used in one main form. Now I would like
to use the same subform in another main form, only the subform then needs a
different record source and the behavior of the subform should at some
points be slightly different which I'm planning to do in VBA.

My questions are: how can I check in my subform by which mainform it is
opened? And secondly: can I safely use the subform in 2 mainforms at the
same time?

Sure you can do that. You can check the name of the main
form:

Select Case Parent.Name
Case "main form 1"
...
Case "main form 2"
...
Case Else
MsgBox "wrong main form or not a subform"
End Select

--
Marsh

Reply With Quote
  #4  
Old   
Arsene@selenium.net
 
Posts: n/a

Default Re: Determine what the main form - 04-03-2011 , 09:42 AM



On Sat, 02 Apr 2011 15:38:24 -0500, Marshall Barton
<marshbarton (AT) wowway (DOT) com> wrote:

Quote:
martin (AT) hotmail (DOT) com> wrote:

I have a subform which I've always used in one main form. Now I would like
to use the same subform in another main form, only the subform then needs a
different record source and the behavior of the subform should at some
points be slightly different which I'm planning to do in VBA.

My questions are: how can I check in my subform by which mainform it is
opened? And secondly: can I safely use the subform in 2 mainforms at the
same time?


Sure you can do that. You can check the name of the main
form:

Select Case Parent.Name
Case "main form 1"
...
Case "main form 2"
...
Case Else
MsgBox "wrong main form or not a subform"
End Select
Marshall,

So, in order to share one subform among multiple mainforms, should the
above code (Select Case Parent.Name, etc.) be inserted in the
subform's "On Load" event?

Reply With Quote
  #5  
Old   
Marshall Barton
 
Posts: n/a

Default Re: Determine what the main form - 04-03-2011 , 12:53 PM



Arsene (AT) selenium (DOT) net wrote:

Quote:
On Sat, 02 Apr 2011 15:38:24 -0500, Marshall Barton wrote:

martin (AT) hotmail (DOT) com> wrote:

I have a subform which I've always used in one main form. Now I would like
to use the same subform in another main form, only the subform then needs a
different record source and the behavior of the subform should at some
points be slightly different which I'm planning to do in VBA.

My questions are: how can I check in my subform by which mainform it is
opened? And secondly: can I safely use the subform in 2 mainforms at the
same time?


Sure you can do that. You can check the name of the main
form:

Select Case Parent.Name
Case "main form 1"
...
Case "main form 2"
...
Case Else
MsgBox "wrong main form or not a subform"
End Select


So, in order to share one subform among multiple mainforms, should the
above code (Select Case Parent.Name, etc.) be inserted in the
subform's "On Load" event?

If you really need the subform to act differently in
different main forms, then you can put that kind of code
anywhere you need to figure out which main form it's in.

Don't forget that subforms are opened before the main form
so don't try to do it too early in the subform. I think the
Load even should be OK but double check it.

I would try to avoid this kind of thing and serioously
consider the tradeoffs of doing this vs creating separate
subforms.

--
Marsh

Reply With Quote
  #6  
Old   
Arsene@selenium.net
 
Posts: n/a

Default Re: Determine what the main form - 04-03-2011 , 01:01 PM



On Sun, 03 Apr 2011 12:53:32 -0500, Marshall Barton
<marshbarton (AT) wowway (DOT) com> wrote:

Quote:
Arsene (AT) selenium (DOT) net wrote:

On Sat, 02 Apr 2011 15:38:24 -0500, Marshall Barton wrote:

martin (AT) hotmail (DOT) com> wrote:

I have a subform which I've always used in one main form. Now I would like
to use the same subform in another main form, only the subform then needs a
different record source and the behavior of the subform should at some
points be slightly different which I'm planning to do in VBA.

My questions are: how can I check in my subform by which mainform it is
opened? And secondly: can I safely use the subform in 2 mainforms at the
same time?


Sure you can do that. You can check the name of the main
form:

Select Case Parent.Name
Case "main form 1"
...
Case "main form 2"
...
Case Else
MsgBox "wrong main form or not a subform"
End Select


So, in order to share one subform among multiple mainforms, should the
above code (Select Case Parent.Name, etc.) be inserted in the
subform's "On Load" event?


If you really need the subform to act differently in
different main forms, then you can put that kind of code
anywhere you need to figure out which main form it's in.

Don't forget that subforms are opened before the main form
so don't try to do it too early in the subform. I think the
Load even should be OK but double check it.

I would try to avoid this kind of thing and serioously
consider the tradeoffs of doing this vs creating separate
subforms.
I have always created separate, dedicated subforms for each mainform,
which has thus far worked OK, witht he only drawback it sometimes (in
larger applications) results in the creation of a lot of forms, which
I was trying to avoid (as one of several ways to decrease file size),
but perhaps you are right and it might not be worth it for the
relatively minuscule decrease in file size.

Thanks !!

Reply With Quote
  #7  
Old   
Marshall Barton
 
Posts: n/a

Default Re: Determine what the main form - 04-03-2011 , 05:23 PM



Arsene (AT) selenium (DOT) net wrote:

Quote:
On Sun, 03 Apr 2011 12:53:32 -0500, Marshall Barton
marshbarton (AT) wowway (DOT) com> wrote:

Arsene (AT) selenium (DOT) net wrote:

On Sat, 02 Apr 2011 15:38:24 -0500, Marshall Barton wrote:

martin (AT) hotmail (DOT) com> wrote:

I have a subform which I've always used in one main form. Now I would like
to use the same subform in another main form, only the subform then needs a
different record source and the behavior of the subform should at some
points be slightly different which I'm planning to do in VBA.

My questions are: how can I check in my subform by which mainform it is
opened? And secondly: can I safely use the subform in 2 mainforms at the
same time?


Sure you can do that. You can check the name of the main
form:

Select Case Parent.Name
Case "main form 1"
...
Case "main form 2"
...
Case Else
MsgBox "wrong main form or not a subform"
End Select


So, in order to share one subform among multiple mainforms, should the
above code (Select Case Parent.Name, etc.) be inserted in the
subform's "On Load" event?


If you really need the subform to act differently in
different main forms, then you can put that kind of code
anywhere you need to figure out which main form it's in.

Don't forget that subforms are opened before the main form
so don't try to do it too early in the subform. I think the
Load even should be OK but double check it.

I would try to avoid this kind of thing and serioously
consider the tradeoffs of doing this vs creating separate
subforms.

I have always created separate, dedicated subforms for each mainform,
which has thus far worked OK, witht he only drawback it sometimes (in
larger applications) results in the creation of a lot of forms, which
I was trying to avoid (as one of several ways to decrease file size),
but perhaps you are right and it might not be worth it for the
relatively minuscule decrease in file size.

File size is not a significant tradeoff factor. I think the
major consideration is the maintence confusion of dealing
with several nearly identical form objects vs the difficulty
of keeping things straight in one complex form object. All
I'm saying is that it is something to think about.

--
Marsh

Reply With Quote
  #8  
Old   
 
Posts: n/a

Default Re: Determine what the main form - 04-04-2011 , 10:00 AM



I managed to make this subform work. I did have to set the child and
masterfields in the main form's load event. It works well.

One of the reasons for doing this was to save an almost identical form. And
if I change something in the code I only have to do it once. Also I have a
lot of code in the subform, with direct references to the form, which would
take me quite a while to migrate to a module.

The subform is a standard subform that holds hyperlink values related to the
mainform. It is expected to work for different main form in the same manner.

Martin


"Marshall Barton" schreef in bericht
news5rhp6tp3sj48efg2n9mout2hrcd5ps7k8 (AT) 4ax (DOT) com...

Arsene (AT) selenium (DOT) net wrote:

Quote:
On Sun, 03 Apr 2011 12:53:32 -0500, Marshall Barton
marshbarton (AT) wowway (DOT) com> wrote:

Arsene (AT) selenium (DOT) net wrote:

On Sat, 02 Apr 2011 15:38:24 -0500, Marshall Barton wrote:

martin (AT) hotmail (DOT) com> wrote:

I have a subform which I've always used in one main form. Now I would
like
to use the same subform in another main form, only the subform then
needs a
different record source and the behavior of the subform should at some
points be slightly different which I'm planning to do in VBA.

My questions are: how can I check in my subform by which mainform it is
opened? And secondly: can I safely use the subform in 2 mainforms at
the
same time?


Sure you can do that. You can check the name of the main
form:

Select Case Parent.Name
Case "main form 1"
...
Case "main form 2"
...
Case Else
MsgBox "wrong main form or not a subform"
End Select


So, in order to share one subform among multiple mainforms, should the
above code (Select Case Parent.Name, etc.) be inserted in the
subform's "On Load" event?


If you really need the subform to act differently in
different main forms, then you can put that kind of code
anywhere you need to figure out which main form it's in.

Don't forget that subforms are opened before the main form
so don't try to do it too early in the subform. I think the
Load even should be OK but double check it.

I would try to avoid this kind of thing and serioously
consider the tradeoffs of doing this vs creating separate
subforms.

I have always created separate, dedicated subforms for each mainform,
which has thus far worked OK, witht he only drawback it sometimes (in
larger applications) results in the creation of a lot of forms, which
I was trying to avoid (as one of several ways to decrease file size),
but perhaps you are right and it might not be worth it for the
relatively minuscule decrease in file size.

File size is not a significant tradeoff factor. I think the
major consideration is the maintence confusion of dealing
with several nearly identical form objects vs the difficulty
of keeping things straight in one complex form object. All
I'm saying is that it is something to think about.

--
Marsh

Reply With Quote
  #9  
Old   
Marshall Barton
 
Posts: n/a

Default Re: Determine what the main form - 04-04-2011 , 11:33 AM



<martin (AT) hotmail (DOT) com> wrote:

Quote:
I managed to make this subform work. I did have to set the child and
masterfields in the main form's load event. It works well.

One of the reasons for doing this was to save an almost identical form. And
if I change something in the code I only have to do it once. Also I have a
lot of code in the subform, with direct references to the form, which would
take me quite a while to migrate to a module.

The subform is a standard subform that holds hyperlink values related to the
mainform. It is expected to work for different main form in the same manner.

It's nice to hear that you got it all to work and that you
have put some thought into the tradeoffs of different
approaches.

--
Marsh

Reply With Quote
  #10  
Old   
Arsene@selenium.net
 
Posts: n/a

Default Re: Determine what the main form - 04-08-2011 , 09:33 AM



On Sun, 03 Apr 2011 17:23:44 -0500, Marshall Barton
<marshbarton (AT) wowway (DOT) com> wrote:

Quote:
Arsene (AT) selenium (DOT) net wrote:

On Sun, 03 Apr 2011 12:53:32 -0500, Marshall Barton
marshbarton (AT) wowway (DOT) com> wrote:

Arsene (AT) selenium (DOT) net wrote:

On Sat, 02 Apr 2011 15:38:24 -0500, Marshall Barton wrote:

martin (AT) hotmail (DOT) com> wrote:

I have a subform which I've always used in one main form. Now I would like
to use the same subform in another main form, only the subform then needs a
different record source and the behavior of the subform should at some
points be slightly different which I'm planning to do in VBA.

My questions are: how can I check in my subform by which mainform it is
opened? And secondly: can I safely use the subform in 2 mainforms at the
same time?


Sure you can do that. You can check the name of the main
form:

Select Case Parent.Name
Case "main form 1"
...
Case "main form 2"
...
Case Else
MsgBox "wrong main form or not a subform"
End Select


So, in order to share one subform among multiple mainforms, should the
above code (Select Case Parent.Name, etc.) be inserted in the
subform's "On Load" event?


If you really need the subform to act differently in
different main forms, then you can put that kind of code
anywhere you need to figure out which main form it's in.

Don't forget that subforms are opened before the main form
so don't try to do it too early in the subform. I think the
Load even should be OK but double check it.

I would try to avoid this kind of thing and serioously
consider the tradeoffs of doing this vs creating separate
subforms.

I have always created separate, dedicated subforms for each mainform,
which has thus far worked OK, witht he only drawback it sometimes (in
larger applications) results in the creation of a lot of forms, which
I was trying to avoid (as one of several ways to decrease file size),
but perhaps you are right and it might not be worth it for the
relatively minuscule decrease in file size.


File size is not a significant tradeoff factor. I think the
major consideration is the maintence confusion of dealing
with several nearly identical form objects vs the difficulty
of keeping things straight in one complex form object. All
I'm saying is that it is something to think about.
I agree. The minuscule decrease in file size is not worth (in my
particular case) the addedd complexity of the subform. I'll stick to
having simpler, dedicated subforms for each of my main forms, however,
I do like knowing I have a choice, something I did not before.

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.