Subform close itself

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form called [form1] and a subform called [subform2]. I have a
toggle button on [form1] to hide/display [subform2] but I would like to add a
command button to [subform2] that will hide itself. I am assuming this is an
option but I just can't seem to get it to work. Any ideas? Thanks again to
everyone in advance.

-John
 
For toggling I have a macro.
Action is SetValue
Item is [subform2].[Visible]
Expression is Not [subform2].[Visible]

to just hide the subform I use this code...

Me![subform2].Visible = False

In the subform I have tried command buttons with code like
Me.Visible = False
but I get a message "you can't close an object that has focus"

I tried to change the focus to form1 and then run the toggle macro but that
caused another error. As you can probably guess I am OK at taking other
people's code and making it work for me, just not generating my own code.
Thank you again for your assistance.

-John

Roger Carlson said:
What have you tried? How do you close it from the main form?

--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L




H0MELY said:
I have a form called [form1] and a subform called [subform2]. I have a
toggle button on [form1] to hide/display [subform2] but I would like to add a
command button to [subform2] that will hide itself. I am assuming this is an
option but I just can't seem to get it to work. Any ideas? Thanks again to
everyone in advance.

-John
 
First of all, I suggest that you can replace your macro with the following
code:

Me![subform2].Visible = Not Me![subform2].Visible

As for hiding it from the subform itself, you have to do 2 things:
1) set the focus to the some control on the main form
2) use full referencing rather than the Me object

Therefore, it would look something like this:

Forms!Form1!Command1.SetFocus
Forms!Form1![subform2].Visible = False

In the above, Command1 is the name of the command button used to toggle, but
it can be ANY control on the main form.

--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L


H0MELY said:
For toggling I have a macro.
Action is SetValue
Item is [subform2].[Visible]
Expression is Not [subform2].[Visible]

to just hide the subform I use this code...

Me![subform2].Visible = False

In the subform I have tried command buttons with code like
Me.Visible = False
but I get a message "you can't close an object that has focus"

I tried to change the focus to form1 and then run the toggle macro but that
caused another error. As you can probably guess I am OK at taking other
people's code and making it work for me, just not generating my own code.
Thank you again for your assistance.

-John

Roger Carlson said:
What have you tried? How do you close it from the main form?

--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L




H0MELY said:
I have a form called [form1] and a subform called [subform2]. I have a
toggle button on [form1] to hide/display [subform2] but I would like
to
add a
command button to [subform2] that will hide itself. I am assuming
this is
an
option but I just can't seem to get it to work. Any ideas? Thanks
again
to
everyone in advance.

-John
 
Roger, thanks a ton for the guidance. I haven't yet tried the code but
logically it makes sense. Actually maybe you can suggest a good VB, VBA or
ACCESS VBA book. I learn best by examples and tutorials. I bought one book
but it is more geared as a reference than instruction manual. I have Office
2003 Pro and Visual Studio.net ver 2003. Again thanks for all of your
assistance.

-John

Roger Carlson said:
First of all, I suggest that you can replace your macro with the following
code:

Me![subform2].Visible = Not Me![subform2].Visible

As for hiding it from the subform itself, you have to do 2 things:
1) set the focus to the some control on the main form
2) use full referencing rather than the Me object

Therefore, it would look something like this:

Forms!Form1!Command1.SetFocus
Forms!Form1![subform2].Visible = False

In the above, Command1 is the name of the command button used to toggle, but
it can be ANY control on the main form.

--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L


H0MELY said:
For toggling I have a macro.
Action is SetValue
Item is [subform2].[Visible]
Expression is Not [subform2].[Visible]

to just hide the subform I use this code...

Me![subform2].Visible = False

In the subform I have tried command buttons with code like
Me.Visible = False
but I get a message "you can't close an object that has focus"

I tried to change the focus to form1 and then run the toggle macro but that
caused another error. As you can probably guess I am OK at taking other
people's code and making it work for me, just not generating my own code.
Thank you again for your assistance.

-John

Roger Carlson said:
What have you tried? How do you close it from the main form?

--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L




I have a form called [form1] and a subform called [subform2]. I have a
toggle button on [form1] to hide/display [subform2] but I would like to
add a
command button to [subform2] that will hide itself. I am assuming this is
an
option but I just can't seem to get it to work. Any ideas? Thanks again
to
everyone in advance.

-John
 
A good book that has lots of samples is Access Cookbook by Ken Getz, Paul
Litwin, and Andy Baron

There are also a bunch of samples and tutorials on my website.

--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L


H0MELY said:
Roger, thanks a ton for the guidance. I haven't yet tried the code but
logically it makes sense. Actually maybe you can suggest a good VB, VBA or
ACCESS VBA book. I learn best by examples and tutorials. I bought one book
but it is more geared as a reference than instruction manual. I have Office
2003 Pro and Visual Studio.net ver 2003. Again thanks for all of your
assistance.

-John

Roger Carlson said:
First of all, I suggest that you can replace your macro with the following
code:

Me![subform2].Visible = Not Me![subform2].Visible

As for hiding it from the subform itself, you have to do 2 things:
1) set the focus to the some control on the main form
2) use full referencing rather than the Me object

Therefore, it would look something like this:

Forms!Form1!Command1.SetFocus
Forms!Form1![subform2].Visible = False

In the above, Command1 is the name of the command button used to toggle, but
it can be ANY control on the main form.

--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L


H0MELY said:
For toggling I have a macro.
Action is SetValue
Item is [subform2].[Visible]
Expression is Not [subform2].[Visible]

to just hide the subform I use this code...

Me![subform2].Visible = False

In the subform I have tried command buttons with code like
Me.Visible = False
but I get a message "you can't close an object that has focus"

I tried to change the focus to form1 and then run the toggle macro but that
caused another error. As you can probably guess I am OK at taking other
people's code and making it work for me, just not generating my own code.
Thank you again for your assistance.

-John

:

What have you tried? How do you close it from the main form?

--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L




I have a form called [form1] and a subform called [subform2]. I
have
a
toggle button on [form1] to hide/display [subform2] but I would
like
to
add a
command button to [subform2] that will hide itself. I am assuming this is
an
option but I just can't seem to get it to work. Any ideas?
Thanks
again
to
everyone in advance.

-John
 
Roger...you rule. Thanks again for everything...I am going to stop by
Microscenter on the way home tonigyht and pick up a copy. I'll also check
out your site tonight...I am sure you will have lots of good stuff for me.
Thanks so much again.

-John

Roger Carlson said:
A good book that has lots of samples is Access Cookbook by Ken Getz, Paul
Litwin, and Andy Baron

There are also a bunch of samples and tutorials on my website.

--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L


H0MELY said:
Roger, thanks a ton for the guidance. I haven't yet tried the code but
logically it makes sense. Actually maybe you can suggest a good VB, VBA or
ACCESS VBA book. I learn best by examples and tutorials. I bought one book
but it is more geared as a reference than instruction manual. I have Office
2003 Pro and Visual Studio.net ver 2003. Again thanks for all of your
assistance.

-John

Roger Carlson said:
First of all, I suggest that you can replace your macro with the following
code:

Me![subform2].Visible = Not Me![subform2].Visible

As for hiding it from the subform itself, you have to do 2 things:
1) set the focus to the some control on the main form
2) use full referencing rather than the Me object

Therefore, it would look something like this:

Forms!Form1!Command1.SetFocus
Forms!Form1![subform2].Visible = False

In the above, Command1 is the name of the command button used to toggle, but
it can be ANY control on the main form.

--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L


For toggling I have a macro.
Action is SetValue
Item is [subform2].[Visible]
Expression is Not [subform2].[Visible]

to just hide the subform I use this code...

Me![subform2].Visible = False

In the subform I have tried command buttons with code like
Me.Visible = False
but I get a message "you can't close an object that has focus"

I tried to change the focus to form1 and then run the toggle macro but
that
caused another error. As you can probably guess I am OK at taking other
people's code and making it work for me, just not generating my own code.
Thank you again for your assistance.

-John

:

What have you tried? How do you close it from the main form?

--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L




I have a form called [form1] and a subform called [subform2]. I have
a
toggle button on [form1] to hide/display [subform2] but I would like
to
add a
command button to [subform2] that will hide itself. I am assuming
this is
an
option but I just can't seem to get it to work. Any ideas? Thanks
again
to
everyone in advance.

-John
 
Homely,

Other good ways to learn the basics of VBA are to create command buttons
with the wizard (View, Toolbox, and toggle on the button with the wand and
starts), and study the code it creates, and study the code behind the forms
in the sample Northwind application (Help, Sample Databases).

Sprinks

H0MELY said:
Roger...you rule. Thanks again for everything...I am going to stop by
Microscenter on the way home tonigyht and pick up a copy. I'll also check
out your site tonight...I am sure you will have lots of good stuff for me.
Thanks so much again.

-John

Roger Carlson said:
A good book that has lots of samples is Access Cookbook by Ken Getz, Paul
Litwin, and Andy Baron

There are also a bunch of samples and tutorials on my website.

--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L


H0MELY said:
Roger, thanks a ton for the guidance. I haven't yet tried the code but
logically it makes sense. Actually maybe you can suggest a good VB, VBA or
ACCESS VBA book. I learn best by examples and tutorials. I bought one book
but it is more geared as a reference than instruction manual. I have Office
2003 Pro and Visual Studio.net ver 2003. Again thanks for all of your
assistance.

-John

:

First of all, I suggest that you can replace your macro with the following
code:

Me![subform2].Visible = Not Me![subform2].Visible

As for hiding it from the subform itself, you have to do 2 things:
1) set the focus to the some control on the main form
2) use full referencing rather than the Me object

Therefore, it would look something like this:

Forms!Form1!Command1.SetFocus
Forms!Form1![subform2].Visible = False

In the above, Command1 is the name of the command button used to toggle, but
it can be ANY control on the main form.

--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L


For toggling I have a macro.
Action is SetValue
Item is [subform2].[Visible]
Expression is Not [subform2].[Visible]

to just hide the subform I use this code...

Me![subform2].Visible = False

In the subform I have tried command buttons with code like
Me.Visible = False
but I get a message "you can't close an object that has focus"

I tried to change the focus to form1 and then run the toggle macro but
that
caused another error. As you can probably guess I am OK at taking other
people's code and making it work for me, just not generating my own code.
Thank you again for your assistance.

-John

:

What have you tried? How do you close it from the main form?

--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L




I have a form called [form1] and a subform called [subform2]. I have
a
toggle button on [form1] to hide/display [subform2] but I would like
to
add a
command button to [subform2] that will hide itself. I am assuming
this is
an
option but I just can't seem to get it to work. Any ideas? Thanks
again
to
everyone in advance.

-John
 
What does your code look like for the Toggle Buttion on the [form1]? I have
a Command Button on the Subform that closes it's self but can't seem to get
the toggle buttion on the form1 to work. Which Event Procedure do you use to
open the subform and which one do you use to close the subform?

LCSIV
 
Back
Top