Please Help?! Hiding Subform

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

Guest

How can I hide a subform until a text box has some value inputed in to it.
If the text box is null subform visible = no
Else if text box isn't null subform visible = yes

Thanx guys!
 
Try this

If not isnull(Me.TextBoxName) and Me.TextBoxName <> "" then
me.SubFormName.visible = True
Else
me.SubFormName.visible = False
End If

Put this code on the after update event of the text box, also if you move
between records, and you want the sub form to change the visibility, then
create a seprate function with the code above, and call this function fron
two places
1. the after update event of the text box
2. The On current event of the form
 
Hi, Ashley.
How can I hide a subform until a text box has some value inputed in to it.
If the text box is null subform visible = no
Else if text box isn't null subform visible = yes

Use the form's OnCurrent( ) event and the text box's OnAfterUpdate( ) event
to check the value in the text box, and set the subform's Visible Property
appropriately. Try:

Private Sub Form_Current()

On Error GoTo ErrHandler

If (Nz(Me!txtSomeValue.Value, "") = "") Then
Me!MySubForm.Visible = False
Else
Me!MySubForm.Visible = True
End If

Exit Sub

ErrHandler:

MsgBox "Error in Form_Current( ) ." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & vbCrLf & Err.Description
Err.Clear

End Sub

Private Sub txtSomeValue_AfterUpdate()

On Error GoTo ErrHandler

If (Nz(Me!txtSomeValue.Value, "") = "") Then
Me!MySubForm.Visible = False
Else
Me!MySubForm.Visible = True
End If

Exit Sub

ErrHandler:

MsgBox "Error in txtSomeValue_AfterUpdate( )." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & vbCrLf & Err.Description
Err.Clear

End Sub

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.
 
It would be better to create one function under the form, and call it from
both places, the On current and the after update, or create the validation in
one place and call this sub from the other sub, that way you need to maintain
it in one place only

Private Sub Form_Current()

On Error GoTo ErrHandler

If (Nz(Me!txtSomeValue.Value, "") = "") Then
Me!MySubForm.Visible = False
Else
Me!MySubForm.Visible = True
End If

Exit Sub

ErrHandler:

MsgBox "Error in Form_Current( ) ." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & vbCrLf & Err.Description
Err.Clear

End Sub

Private Sub txtSomeValue_AfterUpdate()

On Error GoTo ErrHandler

call Form_Current

ErrHandler:

MsgBox "Error in txtSomeValue_AfterUpdate( )." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & vbCrLf & Err.Description
Err.Clear

End Sub
 
Hi, Ofer.

I agree with you. However, the examples I provide serve two additional
purposes, so I typically don't give examples that are identical to the way I
write code. (As I'm sure you write error handling into your code, yet you
don't provide it in your examples.) The two additional purposes are for
future researchers and for teaching new coders.

You'll notice that each procedure is self-contained, in that it requires no
additional code to make it work. Many people search the archives for
previously answered questions for solutions, hoping to find exactly what
they need. Much of the time, the discovered code is "close," but not "close
enough." These folks can take what they need and manipulate it further, but
they don't necessarily have to copy all of the code provided, nor hunt for
more of the necessary pieces in order to get something that works.

The other purpose is for teaching new coders. I try to provide the code at
it's simplest, so there's as little confusion as possible. And while many
of the people requesting help in the newsgroups will just blindly copy and
paste whatever they're given, some will examine the code to try to
understand it. If they do, they'll usually notice something important --
which I never mention when I offer the code. If the questioner replies back
with a comment or a question about the code, then I know they've tried to
learn something and I can offer more.

It's the concept: Give a man a fish and he'll eat for a day. Teach a man
to fish and he'll eat for a lifetime. With enough working examples and
practice, these folks won't be asking for help from others. They'll be
giving it.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.
 
Thanks Gunny, as you can see I don't have such a long experiance with the
discussion group, and I have alot to learn.
This is what it all about, learning, getting and giving back.
Thanks.
 
Hi, Ofer.

You've accomplished a lot in a short time. Congratulations on earning your
second bronze badge. Of the newsgroups we monitor, only two other people
have been able to accomplish that in the nearly 16 months that the Microsoft
Online Community has been in existance: Peo Sjoblom and Duke Carey. And it
appears that you will beat their records when you earn a few more bronze
badges in the near future.

Well done!

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.


Ofer said:
Thanks Gunny, as you can see I don't have such a long experiance with the
discussion group, and I have alot to learn.
This is what it all about, learning, getting and giving back.
Thanks.
 
Back
Top