Visible (1 Viewer)

kitty77

Registered User.
Local time
Today, 10:31
Joined
May 27, 2019
Messages
693
I'm using the following code on a form and it works perfect but not on my report?

Private Sub Report_Current()
If [Mfrequency] = "Steve" Then [Text32].Visible = True Else [Text32].Visible = False
End Sub

What am I doing wrong?
 

Ranman256

Well-known member
Local time
Today, 10:31
Joined
Apr 9, 2015
Messages
4,339
[Text32].Visible=me.Mfrequency= "Steve"
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:31
Joined
May 7, 2009
Messages
19,169
you can use Conditional Format or
Format Event of the Detail Section.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 10:31
Joined
Feb 19, 2002
Messages
42,970
Use arnel's first suggestion of conditional formatting.
 

kitty77

Registered User.
Local time
Today, 10:31
Joined
May 27, 2019
Messages
693
I would like to know why it does not work on format in the detail section?
If [Mfrequency] = "Steve" Then [Text32].Visible = True Else [Text32].Visible = False
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 10:31
Joined
May 21, 2018
Messages
8,463
you can make something look invisible using formatting if you set the foreground and background equal to the sections background. It is not really invisible, but it appears to be.
 

kitty77

Registered User.
Local time
Today, 10:31
Joined
May 27, 2019
Messages
693
Yes but I'm just looking to make only one field be invisible when that condition is met. Like I said, it works fine on a form and not on a report?
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 10:31
Joined
Feb 19, 2002
Messages
42,970
Continuous forms are multiple instances of a SINGLE form. That single form can have only one set of properties for all visible rows. Therefore, when you do formatting using VBA, it affects ALL visible rows. Conditional formatting was added to overcome this problem. The condition needs to go into the control you want to affect, not the control whose value you want to use.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 10:31
Joined
May 21, 2018
Messages
8,463
In this example I make Thorpe Steven's first name look blank. I set conditional formatting where first name = Steven
Steven Thorpe.png

In this case I set the textbox and forecolor to white where first name = "Steven"
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 10:31
Joined
May 21, 2018
Messages
8,463
Continuous forms are multiple instances of a SINGLE form. That single form can have only one set of properties for all visible rows. Therefore, when you do formatting using VBA, it affects ALL visible rows.
Although conditional formatting tends to be an easier and more reliable solution, the above is only partially true. Each row in a continuous form or report is Painted. So you can change the properties between each paint event. This works well on a report, but can be less reliable on a form where you are interacting and continuously causing a repaint event. However the below is done without any conditional formatting. I modified the row where first name = steven. I made the last name appear hidden and painted the email. The trick is you have to set the properties back when the condition is not met.
Code:
Private Sub Detail_Paint()
  If Me.First_Name = "Steven" Then
    Me.E_mail_Address.BackColor = vbRed
    Me.Last_Name.ForeColor = vbWhite
    Me.Last_Name.BorderStyle = 0
   
  Else
    Me.E_mail_Address.BackColor = vbWhite
    Me.Last_Name.FontBold = False
    Me.Last_Name.ForeColor = vbBlack
    Me.Last_Name.BorderStyle = 1
  End If
End Sub
FormOnPaint.png


However, if you use the on paint method for your report you still cannot use the visible property. You are stuck with making it appear invisisble.
 

kitty77

Registered User.
Local time
Today, 10:31
Joined
May 27, 2019
Messages
693
Although conditional formatting tends to be an easier and more reliable solution, the above is only partially true. Each row in a continuous form or report is Painted. So you can change the properties between each paint event. This works well on a report, but can be less reliable on a form where you are interacting and continuously causing a repaint event. However the below is done without any conditional formatting. I modified the row where first name = steven. I made the last name appear hidden and painted the email. The trick is you have to set the properties back when the condition is not met.
Code:
Private Sub Detail_Paint()
  If Me.First_Name = "Steven" Then
    Me.E_mail_Address.BackColor = vbRed
    Me.Last_Name.ForeColor = vbWhite
    Me.Last_Name.BorderStyle = 0
  
  Else
    Me.E_mail_Address.BackColor = vbWhite
    Me.Last_Name.FontBold = False
    Me.Last_Name.ForeColor = vbBlack
    Me.Last_Name.BorderStyle = 1
  End If
End Sub
View attachment 94110

However, if you use the on paint method for your report you still cannot use the visible property. You are stuck with making it appear invisisble.
Any way to make the font be transparent? I'm using alt colors for the rows and the white font show on the gray row.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 10:31
Joined
May 21, 2018
Messages
8,463
No, there is no transparent property for the font. You can write some code to figure out what the alternating color is and set it to that, but that is going to get convoluted. In that case I always do away with the alternate background color.
Potentially you could use an Iff condition in the control
=iiff ([Mfrequency] = "Steve",[mfrequency],Null)
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 09:31
Joined
Feb 28, 2001
Messages
26,999
My question is whether the control of interest is visible on a PRINTED or DISPLAYED report. (It makes a difference.) No questions about the fact that it works on a form.
 

Users who are viewing this thread

Top Bottom