INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Hiding Controls on Report

Hiding Controls on Report

(OP)
Well, I've looked through the archive and haven't found a solution. I'm trying to use the following code to hide/unhide report controls based on specific criteria. Curiously this same method works just fine on a different report.


CODE

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

If Me!txtXLst = "" Or IsNull(Me!txtXLst) Then
' Display/hide cross list information
    Dim ctl As Control
    
    For Each ctl In Me.Controls
        If ctl.Tag = "Visible" Then ctl.Visible = False
    Next ctl
    
Else
    For Each ctl In Me.Controls
        If ctl.Tag = "Visible" Then ctl.Visible = True
    Next ctl
    
End If

End Sub 

Any help with this is much appreciated.

RE: Hiding Controls on Report

I would first try to declare your variable at the top:

CODE

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim ctl As Control

If Me!txtXLst & "" = "" Then
' Display/hide cross list information
    Dim ctl As Control
    
    For Each ctl In Me.Controls 

Have fun.

---- Andy

There is a great need for a sarcasm font.

RE: Hiding Controls on Report

Do the controls have Tag property set to "Visible"?

combo

RE: Hiding Controls on Report

(OP)
Thanks. However, that didn't change the outcome. poo
I must have a typo somewhere or something mismatched. I just don't see any reason why the same approach wouldn't work for multiple reports. I'll go over it again, very carefully. Thanks again.

RE: Hiding Controls on Report

(OP)
Sorry....I didn't see your comment. Yes, I do have "Visible" on each control I want to hide/unhide. But it's one of those areas I need to double check. There just must be one thing misspelled or mismatched or something. Thanks for the thought.

RE: Hiding Controls on Report

I would try something like:

CODE --> vba

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
  Dim ctl As Control

  For Each ctl In Me.Controls
    If ctl.Tag = "Visible" Then
      debug.print ctl.name
      ctl.Visible = Len(Me!txtXLst & "") > 0     
    End If
  Next
End Sub 

Duane
Hook'D on Access
MS Access MVP

RE: Hiding Controls on Report

Duanne,

Wouldn't that be enough of code? (not need for >0 )

CODE

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
  Dim ctl As Control

  For Each ctl In Me.Controls
    If ctl.Tag = "Visible" Then
      debug.print ctl.name
      ctl.Visible = Len(Me!txtXLst & "") '> 0
    End If
  Next
End Sub 

Len(Me!txtXLst & "") would either give a number > 0 (True) or 0 (False)

Have fun.

---- Andy

There is a great need for a sarcasm font.

RE: Hiding Controls on Report

Andy,

I expect your shortened version would be sufficient if not a little geeky.

Duane
Hook'D on Access
MS Access MVP

RE: Hiding Controls on Report

wouldn't this shorten even more

CODE --> VBA

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
  Dim ctl As Control

  For Each ctl In Me.Controls
    'If ctl.Tag = "Visible" Then
      'debug.print ctl.name
      ctl.Visible = (Len(Me!txtXLst & "") and ctl.Tag = "Visible")
    'End If
  Next
End Sub 

RE: Hiding Controls on Report

PWise,

I would be careful about your code messing with the visibility of controls where the tag wasn't "Visible".

Duane
Hook'D on Access
MS Access MVP

RE: Hiding Controls on Report

txtXLst

One would expect a Control whose name is prefaced with txt to be a Textbox...but the XLst part sounds like a Listbox...which is it?

Hope this helps!

There's always more than one way to skin a cat!

All posts/responses based on Access 2003/2007

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close