Percentage figures not transferring from textbox to bound text box correctly (1 Viewer)

chrisjames25

Registered User.
Local time
Today, 17:51
Joined
Dec 1, 2014
Messages
379
Hi All

I have a form whereby a user inputs into unbound textboxes/comboboxes. On clicking thge cmd button these inputs get transferred to bound textboxes.

This all works great other than a textbox whereby I have the format set as a percentage. The unbound txt box is txt_YieldPer and the bound one is Bound_YieldPer.

This is the following code i use to transfer the data:

Code:
Me.Bound_QtyPotted.Value = Me.Txt_QtyPotted.Value
Me.Bound_YieldPer.Value = Me.Txt_YieldPer.Value
Me.Bound_YieldQty.Value = Me.Txt_YieldQty.Value
Me.Bound_DiscPots.Value = Me.Txt_DiscPots.Value
Me.Bound_DiscUnits.Value = Me.Txt_DiscUnits.Value
Me.Bound_PredictedLoss.Value = Me.Txt_PredictedLoss.Value
Me.Bound_MixBatchNo.Value = Me.Txt_MixBatchNo.Value

If i have entered 95% in the unbound txtbox it reads as 0.95 as i toggle through the code but the bound_yieldper becomes 1 rather than 0.95.

Both textboxes are formatted as percentage. The bound field I have tried as an integer with format % and get the result of "1". I have tried it as a decimal formatted as a percentage and get the result of "0". No idea why this is not working like all other textboxes.

Any help would be great
 

Ranman256

Well-known member
Local time
Today, 12:51
Joined
Apr 9, 2015
Messages
4,120
Make sure to NOT use an integer data type.
Assign the vale to a Single type to keep the decimal part.
 

chrisjames25

Registered User.
Local time
Today, 17:51
Joined
Dec 1, 2014
Messages
379
Your a star. Worked a treat.
 

Gasman

Enthusiastic Amateur
Local time
Today, 17:51
Joined
Sep 21, 2011
Messages
10,838
Hi All

I have a form whereby a user inputs into unbound textboxes/comboboxes. On clicking thge cmd button these inputs get transferred to bound textboxes.

This all works great other than a textbox whereby I have the format set as a percentage. The unbound txt box is txt_YieldPer and the bound one is Bound_YieldPer.

This is the following code i use to transfer the data:

Code:
Me.Bound_QtyPotted.Value = Me.Txt_QtyPotted.Value
Me.Bound_YieldPer.Value = Me.Txt_YieldPer.Value
Me.Bound_YieldQty.Value = Me.Txt_YieldQty.Value
Me.Bound_DiscPots.Value = Me.Txt_DiscPots.Value
Me.Bound_DiscUnits.Value = Me.Txt_DiscUnits.Value
Me.Bound_PredictedLoss.Value = Me.Txt_PredictedLoss.Value
Me.Bound_MixBatchNo.Value = Me.Txt_MixBatchNo.Value

If i have entered 95% in the unbound txtbox it reads as 0.95 as i toggle through the code but the bound_yieldper becomes 1 rather than 0.95.

Both textboxes are formatted as percentage. The bound field I have tried as an integer with format % and get the result of "1". I have tried it as a decimal formatted as a percentage and get the result of "0". No idea why this is not working like all other textboxes.

Any help would be great
An integer field is just that, an integer, no decimal places?

 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 12:51
Joined
Feb 19, 2002
Messages
36,837
Why are you entering data into unbound controls? Do you not know that you have complete control over whether a changed record gets saved or not? You would validate the data in the form's BeforeUpdate event and if the data is not valid, you would cancel the save and give the user an error message to help him fix the problem.
Code:
If IsDate(Me.txtDOB) and Me.txtDOB >= Date() -65 Then
Else
    Msgbox "Employee must be less than 65 years old.", vbOKOnly
    Me.txtDOB.SetFocus
    Cancel = True
    Exit Sub
End If

If Me.txtLastName & "" = "" Then
    Msgbox "Last Name is required.", vbOKOnly
    Me.txtLastName.SetFocus
    Cancel = True
    Exit Sub
End If

.....
 

Users who are viewing this thread

Top Bottom