Percentage Field

  • Thread starter Thread starter DS
  • Start date Start date
D

DS

I'm trying to hide a percentage field but it won't hide!

If Me.PercentField > 0 Then
Me.Percentfield.Visible = True
Else Me.PercentField = 0 Then
Me.PercentField.Visible = False
End IF

Any Help Appreciated!
Thanks
DS
 
Rick said:
Where are you putting this code? What event?
Rick,
Its on the On Current Event.
I found the problem Its the ElseIF's
This works...
Private Sub Form_Current()
If Forms!CouponPayment!CouponAmount = 0 Then
Forms!CouponPayment!CouponAmount.Visible = False
End If
If Forms!CouponPayment!CouponAmount > 0 Then
Forms!CouponPayment!CouponAmount.Visible = True
End If
If Forms!CouponPayment!CouponPercent = 0 Then
Forms!CouponPayment!CouponPercent.Visible = False
End If
If Forms!CouponPayment!CouponPercent > 0 Then
Forms!CouponPayment!CouponPercent.Visible = True
End If
End Sub


This doesn't...maybe I didn't have enough EndIF's at the end?
Private Sub Form_Current()
If Forms!CouponPayment!CouponAmount = 0 Then
Forms!CouponPayment!CouponAmount.Visible = False
ElseIf Forms!CouponPayment!CouponAmount > 0 Then
Forms!CouponPayment!CouponAmount.Visible = True
ElseIf Forms!CouponPayment!CouponPercent = 0 Then
Forms!CouponPayment!CouponPercent.Visible = False
ElseIf Forms!CouponPayment!CouponPercent > 0 Then
Forms!CouponPayment!CouponPercent.Visible = True
End If
End Sub

Thanks
DS
 
Hi DS

First, in an If-Then-ElseIf-... construction, only ONE of the statement
blocks will be executed (the first which meets the criteria) so, in your
code if CouponAmount is either equal to or greater than zero, the value in
CouponPercent will not even be checked.

Secondly, if the textboxes are on the current form, you don't need to use
the Forms!CouponPayment syntax, as all of the controls on the form are
within the scope of the form's code module. So, this is sufficient:
Me!CouponPayment.Visible = False
or even simply:
CouponPayment.Visible = False

Thirdly, an If statement eveluates a boolean expression, and the Visible
property is assigned a boolean expression, so you can just cut out the
middle-man:
CouponAmount.Visible = CouponAmount > 0
CouponPercent.Visible = CouponPercent > 0
 
Graham said:
Hi DS

First, in an If-Then-ElseIf-... construction, only ONE of the statement
blocks will be executed (the first which meets the criteria) so, in your
code if CouponAmount is either equal to or greater than zero, the value in
CouponPercent will not even be checked.

Secondly, if the textboxes are on the current form, you don't need to use
the Forms!CouponPayment syntax, as all of the controls on the form are
within the scope of the form's code module. So, this is sufficient:
Me!CouponPayment.Visible = False
or even simply:
CouponPayment.Visible = False

Thirdly, an If statement eveluates a boolean expression, and the Visible
property is assigned a boolean expression, so you can just cut out the
middle-man:
CouponAmount.Visible = CouponAmount > 0
CouponPercent.Visible = CouponPercent > 0
Wow! Thats really nice! Thats what I call coding...and a great answer
to boot!
Thanks
DS
 
Back
Top