VBA Percent Question

  • Thread starter Anthony Viscomi
  • Start date
A

Anthony Viscomi

I have the following code behind an AfterUpdate:
If Me.Front_Style.Value= "Albany" And Me.Front_Material.Value = "Maple" Then
Me.Front_.Value = "-15%"
End if

The format of the control (Front_) is set to Percentage. For some reason I
can only get 0% placed in the Front_ Control. Why?
 
L

Lynn Trapp

What is the datatype of the field that the control [Front_] is bound to? If
it is Long Integer, since -15% is actually -.15, then Access is displaying
the value as 0.
 
A

Anthony Viscomi

DataType =Number
Field Size=Double
Format=Percent
Decimal Places=Auto
Lynn Trapp said:
What is the datatype of the field that the control [Front_] is bound to? If
it is Long Integer, since -15% is actually -.15, then Access is displaying
the value as 0.

--
Lynn Trapp
MS Access MVP
www.ltcomputerdesigns.com
Access Security: www.ltcomputerdesigns.com/Security.htm


Anthony Viscomi said:
I have the following code behind an AfterUpdate:
If Me.Front_Style.Value= "Albany" And Me.Front_Material.Value = "Maple" Then
Me.Front_.Value = "-15%"
End if

The format of the control (Front_) is set to Percentage. For some reason I
can only get 0% placed in the Front_ Control. Why?
 
L

Lynn Trapp

Try changing the name of your form controls to be different from the actual
field name. For example, change Front_ to txtFront_ and then change your
code appropriately.

If Me.txtFront_Style= "Albany" And Me.txtFront_Material= "Maple" Then
Me.txtFront_ = "-15%"
End if


--
Lynn Trapp
MS Access MVP
www.ltcomputerdesigns.com
Access Security: www.ltcomputerdesigns.com/Security.htm


Anthony Viscomi said:
DataType =Number
Field Size=Double
Format=Percent
Decimal Places=Auto
Lynn Trapp said:
What is the datatype of the field that the control [Front_] is bound to? If
it is Long Integer, since -15% is actually -.15, then Access is displaying
the value as 0.

--
Lynn Trapp
MS Access MVP
www.ltcomputerdesigns.com
Access Security: www.ltcomputerdesigns.com/Security.htm


Anthony Viscomi said:
I have the following code behind an AfterUpdate:
If Me.Front_Style.Value= "Albany" And Me.Front_Material.Value =
"Maple"
Then
Me.Front_.Value = "-15%"
End if

The format of the control (Front_) is set to Percentage. For some
reason
 
N

Norman Yuan

In code, you should give it a numeric value, the field's Format setting will
take care of converting it to "xx%". That is,

If ... Then
Me.Front_.value=-0.15
End If

Since you gave it as "-15%", a string value and it cannot be converted to a
number, hence you got 0.

Anthony Viscomi said:
DataType =Number
Field Size=Double
Format=Percent
Decimal Places=Auto
Lynn Trapp said:
What is the datatype of the field that the control [Front_] is bound to? If
it is Long Integer, since -15% is actually -.15, then Access is displaying
the value as 0.

--
Lynn Trapp
MS Access MVP
www.ltcomputerdesigns.com
Access Security: www.ltcomputerdesigns.com/Security.htm


Anthony Viscomi said:
I have the following code behind an AfterUpdate:
If Me.Front_Style.Value= "Albany" And Me.Front_Material.Value =
"Maple"
Then
Me.Front_.Value = "-15%"
End if

The format of the control (Front_) is set to Percentage. For some
reason
 
A

Anthony Viscomi

Norman's solution worked...Thanks!
Norman Yuan said:
In code, you should give it a numeric value, the field's Format setting will
take care of converting it to "xx%". That is,

If ... Then
Me.Front_.value=-0.15
End If

Since you gave it as "-15%", a string value and it cannot be converted to a
number, hence you got 0.

Anthony Viscomi said:
DataType =Number
Field Size=Double
Format=Percent
Decimal Places=Auto
Lynn Trapp said:
What is the datatype of the field that the control [Front_] is bound
to?
If
it is Long Integer, since -15% is actually -.15, then Access is displaying
the value as 0.

--
Lynn Trapp
MS Access MVP
www.ltcomputerdesigns.com
Access Security: www.ltcomputerdesigns.com/Security.htm


I have the following code behind an AfterUpdate:
If Me.Front_Style.Value= "Albany" And Me.Front_Material.Value = "Maple"
Then
Me.Front_.Value = "-15%"
End if

The format of the control (Front_) is set to Percentage. For some
reason
I
can only get 0% placed in the Front_ Control. Why?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top