Hide a subform or text box

M

Mike

Hello all.
I have searched this problem and have tried many examples given .......but
have not been able to get it to work properly, most likely because I am not
familiar with code. I keep getting errors from the module whenever I try to
run the code examples given. The code example would be placed on the
OnCurrent (or) OnCurrent and BeforeUpdate and AfterUpdate.
ANYWAY..............................
I am running Access 2003 with Windows XP. My database is "split".
I want to create a suform on the main form and have it "hidden" if there is
no data in a particular textbox or memo box of the subform
EXAMPLE: Main Form contains the Address, Last Name, First Name, and any
Safety Issues with the address, if any.
In the subform, I have them linked up by Address.
(This part works fine).
After this is where I get stuck. What I want to do is if the is any data in
the textbox or memo box describing the Safety Issues to have the subform or
box show. If there is nothing in the textbox describing the Safety Issues,
the have the subform or textbox be hidden

I would also like to be to have the "Safety Issues" popup in the center of
the screen whenever a particular address is pulled up and there are safety
issues that exists.

And (1) last question.........
Whenever I am looking at examples of code in a module, I see "If
Me.FieldName."
What does "Me." stand for?
I realize this may a stupid question, but as I have said before, I am not
familiar with code and modules.
Thank You All For Your Patience And Help
 
G

Golfinray

On the subform, change the canshrink and cangrow properties to yes. Me. is
the basic identifier for forms, subforms, combo boxes, list boxes, etc. If
you say Me.combo12 you are telling access this is what you are writing code
for. I think the canshrink and cangrow properties will fix your other problem
as well.
 
K

Ken Sheridan

Mike:

I'm afraid the other respondent's suggestion won't work. The CanGrow and
CanShrink properties of controls in forms only apply when printing the form;
they are more often used in reports.

What you are really saying I think is that you want the subform hidden if it
has no row in its underlying recordset, i.e. if there are no safety issues
associated with the current address.

One way to determine this by examining the RecordCount property of the
subform's Recordset property. Firstly, its important to understand how to
refer to a subform from its parent form:

1. The parent form's Controls collection contains a 'subform control'.
This is the control which houses the subform.

2. The subform control has a Form property which returns a reference to the
underlying Form object.

3. A subform's underlying Form object does not form part of the current
database's Forms collection, so you cannot refer to it in the usual way with
Forms("MyForm") as you would an open 'main' form.

In your case you want to set the Visible property of the subform control in
the parent form's Current event procedure, so the code would go like this:

Dim ctrl As Control
Dim frm As Form

Set ctrl = Me.YourSubformControlNameGoesHere
Set frm = ctrl.Form

ctrl.Visible = (frm.Recordset.RecordCount > 0)

An alternative way would be to examine the subform's Address value for Not
Null:

Dim ctrl As Control
Dim frm As Form

Set ctrl = Me.YourSubformControlNameGoesHere
Set frm = ctrl.Form

ctrl.Visible = Not IsNull(frm.[Address])

As for 'Me' strictly speaking it refers to the current instance of a class
in which the code is running, but think of it as a shorthand way of referring
the form or report in whose module the code is running.

Incidentally Report objects have a HasData property which can be used to
hide a subreport when printing a report. Unfortunately forms don't have this
property.

Ken Sheridan
Stafford, England
 
M

Mike

Hi Ken. Thank You for your response.
Below is the code that I was trying to use last night and was giving me so
much grief. On the on current event of the form :

If me.fieldName > 0 then
me.fieldname.visible=false
else
me.fieldname.visible=true
end if

I will try your example later on.
You see, We use an editor function to edit all the resident records. In
there is a text or a memo box that a user would type in the safety issues, if
any. We currently have about 700 residents and ONLY about 20 have safety
issues listed, i.e. dogs or weapons. This textbox or memo is just an area
where the user can type whatever he/she wants to. I am simply trying to have
either the textbox or memo box appear or "popup" in the center of the screen
if there is any data already in the field that would be describing what the
safety issues are whenever and address is pulled up. If there is nothing in
the field then the popup form or text box would not appear.

I know it sounds as if I am rambling on, got some things going on right
now. I try to get your advise to work. THANK YOU AGAIN FOR YOU HELP.

Mike

--
Mike


Ken Sheridan said:
Mike:

I'm afraid the other respondent's suggestion won't work. The CanGrow and
CanShrink properties of controls in forms only apply when printing the form;
they are more often used in reports.

What you are really saying I think is that you want the subform hidden if it
has no row in its underlying recordset, i.e. if there are no safety issues
associated with the current address.

One way to determine this by examining the RecordCount property of the
subform's Recordset property. Firstly, its important to understand how to
refer to a subform from its parent form:

1. The parent form's Controls collection contains a 'subform control'.
This is the control which houses the subform.

2. The subform control has a Form property which returns a reference to the
underlying Form object.

3. A subform's underlying Form object does not form part of the current
database's Forms collection, so you cannot refer to it in the usual way with
Forms("MyForm") as you would an open 'main' form.

In your case you want to set the Visible property of the subform control in
the parent form's Current event procedure, so the code would go like this:

Dim ctrl As Control
Dim frm As Form

Set ctrl = Me.YourSubformControlNameGoesHere
Set frm = ctrl.Form

ctrl.Visible = (frm.Recordset.RecordCount > 0)

An alternative way would be to examine the subform's Address value for Not
Null:

Dim ctrl As Control
Dim frm As Form

Set ctrl = Me.YourSubformControlNameGoesHere
Set frm = ctrl.Form

ctrl.Visible = Not IsNull(frm.[Address])

As for 'Me' strictly speaking it refers to the current instance of a class
in which the code is running, but think of it as a shorthand way of referring
the form or report in whose module the code is running.

Incidentally Report objects have a HasData property which can be used to
hide a subreport when printing a report. Unfortunately forms don't have this
property.

Ken Sheridan
Stafford, England

Mike said:
Hello all.
I have searched this problem and have tried many examples given .......but
have not been able to get it to work properly, most likely because I am not
familiar with code. I keep getting errors from the module whenever I try to
run the code examples given. The code example would be placed on the
OnCurrent (or) OnCurrent and BeforeUpdate and AfterUpdate.
ANYWAY..............................
I am running Access 2003 with Windows XP. My database is "split".
I want to create a suform on the main form and have it "hidden" if there is
no data in a particular textbox or memo box of the subform
EXAMPLE: Main Form contains the Address, Last Name, First Name, and any
Safety Issues with the address, if any.
In the subform, I have them linked up by Address.
(This part works fine).
After this is where I get stuck. What I want to do is if the is any data in
the textbox or memo box describing the Safety Issues to have the subform or
box show. If there is nothing in the textbox describing the Safety Issues,
the have the subform or textbox be hidden

I would also like to be to have the "Safety Issues" popup in the center of
the screen whenever a particular address is pulled up and there are safety
issues that exists.

And (1) last question.........
Whenever I am looking at examples of code in a module, I see "If
Me.FieldName."
What does "Me." stand for?
I realize this may a stupid question, but as I have said before, I am not
familiar with code and modules.
Thank You All For Your Patience And Help
 
K

Ken Sheridan

Mmmm! Not a good design. You'd be much better off with a properly
structured SafetyIssues table and a ResidentsSafetyIssues table to model the
many-to-many relationship between Residents and SafetyIssues. That way you'd
be able to extract quantifiable information on such issues from the database.

However, putting that to one side, from what you say it doesn't sound like
you are talking about a subform at all. A subform is a form embedded within
a parent form (see the Orders form in the sample Northwind database for an
example; it has an Order Details subform within it). What you are describing
sound more like a linked popup form. In which case:

1. Base Safety Issues popup form (making sure its Popup property is True
(Yes)) on a query which references the main Residents form e.g.

SELECT SafetyIssues FROM YourTable WHERE Address = Forms!frmResidents!Address;

2. In the Load event procedure of the Residents form open the Safety Issues
form with:

DoCmd.OpenForm "frmSafetyIssues"

3. In the Current event procedure of the residents form put:

Dim frm As Form
Dim ctrl As Control

Set frm = Forms("frmSafetyIssues")
Set ctrl = frm("NameOfTextBoxControlOnSafetyIssuesForm")

frm.Requery
frm.Visible = Not IsNull(ctrl)

4. In the Close event procedure of the residents form put:

DoCmd.Close acForm, "frmSafetyIssues"

Ken Sheridan
Stafford, England

Mike said:
Hi Ken. Thank You for your response.
Below is the code that I was trying to use last night and was giving me so
much grief. On the on current event of the form :

If me.fieldName > 0 then
me.fieldname.visible=false
else
me.fieldname.visible=true
end if

I will try your example later on.
You see, We use an editor function to edit all the resident records. In
there is a text or a memo box that a user would type in the safety issues, if
any. We currently have about 700 residents and ONLY about 20 have safety
issues listed, i.e. dogs or weapons. This textbox or memo is just an area
where the user can type whatever he/she wants to. I am simply trying to have
either the textbox or memo box appear or "popup" in the center of the screen
if there is any data already in the field that would be describing what the
safety issues are whenever and address is pulled up. If there is nothing in
the field then the popup form or text box would not appear.

I know it sounds as if I am rambling on, got some things going on right
now. I try to get your advise to work. THANK YOU AGAIN FOR YOU HELP.

Mike

--
Mike


Ken Sheridan said:
Mike:

I'm afraid the other respondent's suggestion won't work. The CanGrow and
CanShrink properties of controls in forms only apply when printing the form;
they are more often used in reports.

What you are really saying I think is that you want the subform hidden if it
has no row in its underlying recordset, i.e. if there are no safety issues
associated with the current address.

One way to determine this by examining the RecordCount property of the
subform's Recordset property. Firstly, its important to understand how to
refer to a subform from its parent form:

1. The parent form's Controls collection contains a 'subform control'.
This is the control which houses the subform.

2. The subform control has a Form property which returns a reference to the
underlying Form object.

3. A subform's underlying Form object does not form part of the current
database's Forms collection, so you cannot refer to it in the usual way with
Forms("MyForm") as you would an open 'main' form.

In your case you want to set the Visible property of the subform control in
the parent form's Current event procedure, so the code would go like this:

Dim ctrl As Control
Dim frm As Form

Set ctrl = Me.YourSubformControlNameGoesHere
Set frm = ctrl.Form

ctrl.Visible = (frm.Recordset.RecordCount > 0)

An alternative way would be to examine the subform's Address value for Not
Null:

Dim ctrl As Control
Dim frm As Form

Set ctrl = Me.YourSubformControlNameGoesHere
Set frm = ctrl.Form

ctrl.Visible = Not IsNull(frm.[Address])

As for 'Me' strictly speaking it refers to the current instance of a class
in which the code is running, but think of it as a shorthand way of referring
the form or report in whose module the code is running.

Incidentally Report objects have a HasData property which can be used to
hide a subreport when printing a report. Unfortunately forms don't have this
property.

Ken Sheridan
Stafford, England

Mike said:
Hello all.
I have searched this problem and have tried many examples given .......but
have not been able to get it to work properly, most likely because I am not
familiar with code. I keep getting errors from the module whenever I try to
run the code examples given. The code example would be placed on the
OnCurrent (or) OnCurrent and BeforeUpdate and AfterUpdate.
ANYWAY..............................
I am running Access 2003 with Windows XP. My database is "split".
I want to create a suform on the main form and have it "hidden" if there is
no data in a particular textbox or memo box of the subform
EXAMPLE: Main Form contains the Address, Last Name, First Name, and any
Safety Issues with the address, if any.
In the subform, I have them linked up by Address.
(This part works fine).
After this is where I get stuck. What I want to do is if the is any data in
the textbox or memo box describing the Safety Issues to have the subform or
box show. If there is nothing in the textbox describing the Safety Issues,
the have the subform or textbox be hidden

I would also like to be to have the "Safety Issues" popup in the center of
the screen whenever a particular address is pulled up and there are safety
issues that exists.

And (1) last question.........
Whenever I am looking at examples of code in a module, I see "If
Me.FieldName."
What does "Me." stand for?
I realize this may a stupid question, but as I have said before, I am not
familiar with code and modules.
Thank You All For Your Patience And Help
 
M

Mike

Ken. Thank You so much for your assistance. I will give your examples a
try......If I have an issues, I will be replying again. Just so you know the
background of the structure.............................

I have a Resident's table that holds all the information in it including
the text box describing what the safety issue is.
I have a seperate table which is with a drop down having (2) choices.
Officer Safety Issue and No Officer Safety Issues.
Originally I had a command button on the Main Resident screen that a user
could hit to open up the Officer Safety Issues form. This is not editable
because as I said before, we use an editing form to edit all the improtant
information for the residents. Also, I had set the conditional formatting for
the (1) text box to fill with GREEN if it stated "No Officer Safety Issues"
and then have the fill change to RED if the text box said "Officer Safety
Issue"
When the user would click on the command button, to open the Officer Safety
Issues form, in the would be the address, last name, and a text box
describing whatever safety issues there may be. You see, we don't just want
to know if there are issues or not, BUT more importantly, we need to know
what the issues really are. That is why we have the text box describing them
and it is only "that" text box that I want to pop up (or) to show whenever it
is true to an address that is accessed.
Regarding the sub form, I was able to get it to show up on the side, but it
would always be there, even if there was no data in the box. The sub form
operated correctly, I was just lookikng for a way to have it hide if the was
no data in the "HAZZARDS" textbox.
I do believe that for the "HAZZARDS", it may be more benifitial to have it
popup in the center of the screen. BUT I also have other ideas to use the
above described subform for, so.............the saga continues.
I am greatful for your feedback and help.
I will give your examples a try............but not tonight.

THANK YOU,
Mike
--
Mike


Ken Sheridan said:
Mmmm! Not a good design. You'd be much better off with a properly
structured SafetyIssues table and a ResidentsSafetyIssues table to model the
many-to-many relationship between Residents and SafetyIssues. That way you'd
be able to extract quantifiable information on such issues from the database.

However, putting that to one side, from what you say it doesn't sound like
you are talking about a subform at all. A subform is a form embedded within
a parent form (see the Orders form in the sample Northwind database for an
example; it has an Order Details subform within it). What you are describing
sound more like a linked popup form. In which case:

1. Base Safety Issues popup form (making sure its Popup property is True
(Yes)) on a query which references the main Residents form e.g.

SELECT SafetyIssues FROM YourTable WHERE Address = Forms!frmResidents!Address;

2. In the Load event procedure of the Residents form open the Safety Issues
form with:

DoCmd.OpenForm "frmSafetyIssues"

3. In the Current event procedure of the residents form put:

Dim frm As Form
Dim ctrl As Control

Set frm = Forms("frmSafetyIssues")
Set ctrl = frm("NameOfTextBoxControlOnSafetyIssuesForm")

frm.Requery
frm.Visible = Not IsNull(ctrl)

4. In the Close event procedure of the residents form put:

DoCmd.Close acForm, "frmSafetyIssues"

Ken Sheridan
Stafford, England

Mike said:
Hi Ken. Thank You for your response.
Below is the code that I was trying to use last night and was giving me so
much grief. On the on current event of the form :

If me.fieldName > 0 then
me.fieldname.visible=false
else
me.fieldname.visible=true
end if

I will try your example later on.
You see, We use an editor function to edit all the resident records. In
there is a text or a memo box that a user would type in the safety issues, if
any. We currently have about 700 residents and ONLY about 20 have safety
issues listed, i.e. dogs or weapons. This textbox or memo is just an area
where the user can type whatever he/she wants to. I am simply trying to have
either the textbox or memo box appear or "popup" in the center of the screen
if there is any data already in the field that would be describing what the
safety issues are whenever and address is pulled up. If there is nothing in
the field then the popup form or text box would not appear.

I know it sounds as if I am rambling on, got some things going on right
now. I try to get your advise to work. THANK YOU AGAIN FOR YOU HELP.

Mike

--
Mike


Ken Sheridan said:
Mike:

I'm afraid the other respondent's suggestion won't work. The CanGrow and
CanShrink properties of controls in forms only apply when printing the form;
they are more often used in reports.

What you are really saying I think is that you want the subform hidden if it
has no row in its underlying recordset, i.e. if there are no safety issues
associated with the current address.

One way to determine this by examining the RecordCount property of the
subform's Recordset property. Firstly, its important to understand how to
refer to a subform from its parent form:

1. The parent form's Controls collection contains a 'subform control'.
This is the control which houses the subform.

2. The subform control has a Form property which returns a reference to the
underlying Form object.

3. A subform's underlying Form object does not form part of the current
database's Forms collection, so you cannot refer to it in the usual way with
Forms("MyForm") as you would an open 'main' form.

In your case you want to set the Visible property of the subform control in
the parent form's Current event procedure, so the code would go like this:

Dim ctrl As Control
Dim frm As Form

Set ctrl = Me.YourSubformControlNameGoesHere
Set frm = ctrl.Form

ctrl.Visible = (frm.Recordset.RecordCount > 0)

An alternative way would be to examine the subform's Address value for Not
Null:

Dim ctrl As Control
Dim frm As Form

Set ctrl = Me.YourSubformControlNameGoesHere
Set frm = ctrl.Form

ctrl.Visible = Not IsNull(frm.[Address])

As for 'Me' strictly speaking it refers to the current instance of a class
in which the code is running, but think of it as a shorthand way of referring
the form or report in whose module the code is running.

Incidentally Report objects have a HasData property which can be used to
hide a subreport when printing a report. Unfortunately forms don't have this
property.

Ken Sheridan
Stafford, England

:

Hello all.
I have searched this problem and have tried many examples given .......but
have not been able to get it to work properly, most likely because I am not
familiar with code. I keep getting errors from the module whenever I try to
run the code examples given. The code example would be placed on the
OnCurrent (or) OnCurrent and BeforeUpdate and AfterUpdate.
ANYWAY..............................
I am running Access 2003 with Windows XP. My database is "split".
I want to create a suform on the main form and have it "hidden" if there is
no data in a particular textbox or memo box of the subform
EXAMPLE: Main Form contains the Address, Last Name, First Name, and any
Safety Issues with the address, if any.
In the subform, I have them linked up by Address.
(This part works fine).
After this is where I get stuck. What I want to do is if the is any data in
the textbox or memo box describing the Safety Issues to have the subform or
box show. If there is nothing in the textbox describing the Safety Issues,
the have the subform or textbox be hidden

I would also like to be to have the "Safety Issues" popup in the center of
the screen whenever a particular address is pulled up and there are safety
issues that exists.

And (1) last question.........
Whenever I am looking at examples of code in a module, I see "If
Me.FieldName."
What does "Me." stand for?
I realize this may a stupid question, but as I have said before, I am not
familiar with code and modules.
Thank You All For Your Patience And Help
 

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