Show/Hide a field on a State - ACCESS

Jeen -  
 Jeen -
Hello,

Here, when I generate a report, I would like the empty fields not to be displayed. I am a beginner in coding... but here is what I have tried:

Private Sub TOTAL_FRAIS_BeforeUpdate(Cancel As Integer)
If IsNull(Me.TOTAL_FRAIS.Value) Then
Me.Label32.Visible = False
Me.TRANSPORT_OUT.Visible = False
Me.Label33.Visible = False
Me.TRANSPORT_RETURN.Visible = False
Me.Label34.Visible = False
Me.TOTAL_TRANSPORT.Visible = False
Me.Label42.Visible = False
Me.Label44.Visible = False
Me.Label35.Visible = False
Me.NUMBER_OF_MEALS.Visible = False
Me.Label36.Visible = False
Me.PRICE_PER_MEAL.Visible = False
Me.Label37.Visible = False
Me.TOTAL_MEALS.Visible = False
Me.Label43.Visible = False
Me.Label38.Visible = False
Me.NUMBER_OF_NIGHTS.Visible = False
Me.Label39.Visible = False
Me.PRICE_HOTEL.Visible = False
Me.Label40.Visible = False
Me.TOTAL_ACCOMMODATION.Visible = False
Me.Label41.Visible = False
Me.TOTAL_EXPENSES.Visible = False
Me.Label31.Visible = False
End If
End Sub

By any chance, could you help me by telling me what is wrong?
THANK YOU VERY MUCH!

Configuration: Windows 7 / Firefox 5.0

7 answers

Jean_Jacques
 
Hello JEEN,

The solution lies in the True/False function.
Here is a specimen as an example:

=IIF([OperationRef]=1,"Gross amount of the sale",IIF([OperationRef]=2,"Gross amount of the sale","Error!"))

Note: This function is often documented with the English equivalent: IIF

You can easily find it on Google
Also see the reference site: http://access.developpez.com/cours/

***
Best regards
Science merely discovers what has always existed.
REEVES Hubert.
0
Jeen
 
Thank you very much for this link. It's very helpful to me! Especially for understanding the VBA code.

However, I can't make the connection between the VraiFaux function and not displaying my fields...

VraiFaux([FieldX]=0; me.[fieldy].visible=false; me.[fieldy].visible=true)?
0
jean_Jacques
 
Good evening Jeen,

By pressing the F1 key, you will access the online help.
Enter: IIF in the intuitive search field.
Note: " " means -> Do not display

Don’t forget to start with the equals sign = (as in EXCEL)

Best regards
***
Science only discovers what has always existed.
REEVES HUBERT.
0
Jeen
 
Hello Jean Jacques,

Thank you for all your valuable advice. It helps!

I'm sorry to bother you again, but I have another problem...

When my function is expressed as below, I get an error message: "Compilation error - Expected: line number or label or statement or end statement" when selecting the first "=" sign
=> =IIf("TRANSPORT_ALLER=0", "", [TRANSPORT_ALLER])

When I put the same function without the first "=", I get an error message: "Compilation error - Expected: ="

I have tried several syntaxes, searched the help, and looked online but I can't find the answer to my problem. I tried including "Private sub... End sub" but nothing works.

Thank you again!!!
0
UJAT4232
 
I apologize, Jeen,
Upon reviewing carefully, I realize that I was mistaken.

In your first post, you were just a hair away from the solution. Indeed,
in your event on Open (if I understood correctly this time), it is necessary to repeat the if/endif syntax as follows:

Private Sub Report_Open(Cancel As Integer)

If IsNull(Me.<field_name>) Then
Label29.Visible = False
End If

DoCmd.Maximize
End Sub

Sorry for the time lost
See you
0
UJAT4232
 
Jeen,
Here is a syntax that (on my end) allows you to hide a field in a state.
It should be entered in the properties of the text box, data/source control tab
=TrueFalse([<field_name>]="""")
0
Jeen
 
Thank you. But I have a circular reference problem, and if I change the control name as suggested, it gives me a “#Error” message on my report...

And otherwise, I was wondering how I can do the same process as you do on the Labels, because in the data tab I don't have a control source but only active tags. I can't enter expressions.

Thank you again.
0
Jeen
 
Thank you for your help!!!

I followed your instructions well. But the empty fields in my state still remain visible. I think there might be a problem with my file. After several different attempts, nothing works.
The only change I made in the code you provided was replacing "IsNull" with "IsEmpty"...

Finally, thank you for your time!
0
Jean_Jacques
 
Good evening Jeen,
The topic of field masking is covered at this link.
I let you discover it:

http://www.vbfrance.com/forum/sujet-CACHER-CHAMP-DANS-ETAT-ACCESS-QD-CELUI-CI_719208.aspx

The proposed solution:

If Not IsNull(Me.Controls("ControlName").value) Then
Me.Controls("ControlName").Visible = True
Me.Controls("Control_Label").Visible = True
Else:
Me.Controls("ControlName").Visible = False
Me.Controls("Control_Label").Visible = False
End If
0
Jean_Jacques Posted messages 1045 Registration date   Status Member Last intervention   112
 
Donc c'est la guerre.
0
Jeen
 
Thank you.
I found this forum as well. I tried again, once by making my fields invisible by default and the other time using If ...then ...else ...end if. In both cases, it doesn't work. I think the codes simply have no impact on my State. I'm pretty sure I did it right. I ran several tests, but nothing works.

Anyway, thank you very much for your help!!!

Private Sub Report_Activate()
If Not IsNull(Me.Controls(TOTAL_FRAIS).Value) Then
Me.Controls(TRANSPORT_ALLER).Visible = True
Me.Controls(Etiquette32).Visible = True
End If
End Sub
0