Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hiding Controls on Report

Status
Not open for further replies.

Amadea

Technical User
Oct 11, 2003
49
US
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.
 
I would first try to declare your variable at the top:

Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)[blue]
Dim ctl As Control[/blue]

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

Have fun.

---- Andy

There is a great need for a sarcasm font.
 
Do the controls have Tag property set to "Visible"?

combo
 
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.
 
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.
 
I would try something like:

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

Duane
Hook'D on Access
MS Access MVP
 
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 & "") [green]'> 0[/green]
    End If
  Next
End Sub

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

Have fun.

---- Andy

There is a great need for a sarcasm font.
 
wouldn't this shorten even more

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

  For Each ctl In Me.Controls
    [COLOR=#73D216]'If ctl.Tag = "Visible" Then
      'debug.print ctl.name[/color]
      ctl.Visible = (Len(Me!txtXLst & "") and ctl.Tag = "Visible")
    [COLOR=#73D216]'End If[/color]
  Next
End Sub
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top