Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RePost?? Please help

Status
Not open for further replies.

wdu94

Programmer
Aug 15, 2001
61
0
0
US
Hello,

I have the datasheet form that form show up data by each orderID.
In the this form I have a payment percentage field. I want to restrict this percentage when the user enter "percentage". The logical is total percentage should be less than 1.

e.g: the user enter first row percentage is: 60%
the user enter second row percentage is: 20%
the user enter third row percentage is: 30% (Should get error here) Can somebody help me out? How?

The following are my codes but doesn't work:

private txtPercent_AfterUpdate()
Dim dblPercent as Double
tmp = dblPercent + txtPercent
If tmp > 1 then
msgbox "The total percentage should be less than 1"
Exit sub
End if
dblPercent = tmp
End Sub

Thanks.

Wdu
 
You define dblPercent as a local variable. It is released from the memory after the procedure is over. Therefore you actually cannot get any total percentage.

Try defining dblPercent at the module level like:

Private dblPercent as double


Seaport
 
Hi, Seaport,

Thanks for your respond. My project basically works. but I can't update info. in the same row.

for example:

first row I enter 50%
second row I enter 25%, if I changed this row from 25% to 50% should be OK, but this case still remember 25%. The means if I changed 25% to 50%, the total percent are:

50% + 25% + 50% I don't know how to modify this code to update info. in the same row. Any ideas?

Thank you very much.
Wdu
 
OK, forget my first response. Try the following code. "tblSource" is the data source of your form. "Percent" is the control source (the field name) of txtPercent. Also, you might need to add criteria in the dsum function.

private txtPercent_BeforeUpdate(cancel as integer)
Dim dblPercent as Double
dblpercent=dsum("Percent","tblsource")
If newrecord then
tmp = dblPercent + txtPercent
else
temp=dblpercent-txtPercent.oldvalue+txtpercent
end if
If tmp > 1 then
msgbox "The total percentage should be less than 1"
cancel=true
End if
End Sub

Seaport
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top