UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Prevent A Control From Being Visible If Its Value Is Null Or = 0, Access 2016    
 
   
InfoHound
post Sep 10 2019, 06:41 AM
Post#1



Posts: 1,155
Joined: 1-December 12



I have a report that has controls in the Report Footer that I don't want to appear in the Print Preview if their value is Null or 0.

I've put this code:
CODE
On Error GoTo ErrHan

    If IsNull(txtMins) Or txtMins = 0 Then
        Me.DayHrs.Visible = False
    End If

ExitErr:
    Exit Sub
ErrHan:
    MsgBox Err.Description, vbInformation, gappName
    Resume ExitErr



in the On Format, On Print and On Paint, but nothing works.

Can this be done?

Thanks
Go to the top of the page
 
Phil_cattivocara...
post Sep 10 2019, 07:00 AM
Post#2



Posts: 348
Joined: 2-April 18



Reading your first line it seems you want to hide/visualize controls in Report footer according their values, but in your code you refer to other control.
Where are txtMins and DayHrs?
If you want to hide something in the Report footer you should write such a code in format event of that section.
CODE
TheControlToHide.Visible = IsNull(theControlToCheck.Value) or theControlToCheck.Value = 0
Please forgive me if I cannot write the real section and event name but Access translate in local language so I have italian sintax.
It could be PageFooter or PageFooterSection (format event)

--------------------
Please forgive in advance my horrible English.
Go to the top of the page
 
BruceM
post Sep 10 2019, 07:18 AM
Post#3


UtterAccess VIP
Posts: 7,959
Joined: 24-May 10
From: Downeast Maine


Just to add a little to what Phil wrote, be sure you are referencing controls and not fields when using the Visible property. You use the txt prefix for the value to check (txtMins), but no prefix for DayHrs. If you have a consistent naming convention, that suggests you are checking the value of controls, then trying to hide a field.

Also, be sure you can compile the code. Without the Me prefix you don't have the advantage of having Access show a list of controls, properties, and methods from which to select. This is one of several advantages to using the Me prefix.

Although testing IsNull or the value is correct, you can use Nz to simplify the test:

If Nz(Me.txtMins,0) = 0

If txtMins is null, the Nz function returns 0 (the second argument).
Go to the top of the page
 
projecttoday
post Sep 10 2019, 07:20 AM
Post#4


UtterAccess VIP
Posts: 10,962
Joined: 10-February 04
From: South Charleston, WV


It would be the Report Footer section. Also, I would preface the control name with "Me".

--------------------
Robert Crouser
Go to the top of the page
 
projecttoday
post Sep 10 2019, 07:24 AM
Post#5


UtterAccess VIP
Posts: 10,962
Joined: 10-February 04
From: South Charleston, WV


Or
If Len(Me.txtMins & "") < 1

Infobound, I hope you realize that in your original code the control is never reset back to visible.

--------------------
Robert Crouser
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    19th September 2019 - 03:28 AM