imjamesw
asked on
How to update a field Part2
Hi All
Previous question
https://www.experts-exchange.com/questions/20789973/update-a-field-on-a-document-with-the-value-from-a-different-doc.html
Ok now I want to subtract some numbers if a request is cancelled
Just a foot note
All fields are Number and Computed
If ApprovalStatus = Cancelled then note.TotalDaysOff(0) is reset to 0
If Not doc Is Nothing Then
doc.HolidaysAH = doc.HolidaysAH(0) - doc.TotalDaysOff(0)
doc.RemainingAH = doc.RemainingCalc(0) +doc.TotalDaysOff(0)
doc.ComputeWithForm True, False
doc.save True, False
Else
Msgbox "No leave document found for this employee"
End If
The above does not work or works inconsitently
I think the best way would be to freate a temp variable grab values and then do the math what do you think
James
Previous question
https://www.experts-exchange.com/questions/20789973/update-a-field-on-a-document-with-the-value-from-a-different-doc.html
Ok now I want to subtract some numbers if a request is cancelled
Just a foot note
All fields are Number and Computed
If ApprovalStatus = Cancelled then note.TotalDaysOff(0) is reset to 0
If Not doc Is Nothing Then
doc.HolidaysAH = doc.HolidaysAH(0) - doc.TotalDaysOff(0)
doc.RemainingAH = doc.RemainingCalc(0) +doc.TotalDaysOff(0)
doc.ComputeWithForm True, False
doc.save True, False
Else
Msgbox "No leave document found for this employee"
End If
The above does not work or works inconsitently
I think the best way would be to freate a temp variable grab values and then do the math what do you think
James
I am not sure if you have given me the correct fields, let me help you to organize it
If note.ApprovalStatus(0) = "Cancelled" then ' Check this string value is same as that for cancel operation
note.TotalDaysOff = 0 ' This will be set in the currently opened approval doc
' Get the leave doc handle to this currently selected employee..
If Not doc Is Nothing Then
doc.HolidaysAH = doc.HolidaysAH(0) - doc.TotalDaysOff(0)
doc.RemainingAH = doc.RemainingCalc(0) + doc.TotalDaysOff(0)
doc.ComputeWithForm True, False
doc.save True, False
Else
Msgbox "No leave document found for this employee"
End If
End If ' ApprovalStatus Check
James clearly specify what are the results/error that you are getting so that it will facilitate me to give you proper guidance.
~Hemanth
If note.ApprovalStatus(0) = "Cancelled" then ' Check this string value is same as that for cancel operation
note.TotalDaysOff = 0 ' This will be set in the currently opened approval doc
' Get the leave doc handle to this currently selected employee..
If Not doc Is Nothing Then
doc.HolidaysAH = doc.HolidaysAH(0) - doc.TotalDaysOff(0)
doc.RemainingAH = doc.RemainingCalc(0) + doc.TotalDaysOff(0)
doc.ComputeWithForm True, False
doc.save True, False
Else
Msgbox "No leave document found for this employee"
End If
End If ' ApprovalStatus Check
James clearly specify what are the results/error that you are getting so that it will facilitate me to give you proper guidance.
~Hemanth
ASKER
Hi Hemanth
I have it working with the following perhaps you could get more info from the code
If Not doc Is Nothing Then
tmpHolidaysAH = doc.HolidaysAH(0) 'This is the number of days used
tmpTotal = note.NewDaysTotal(0) 'This is the number of new days booked
tmpNew = tmpHolidaysAH - tmpTotal 'This will reset the value removing the value that was added when approved
doc.TotalDaysOffCalc = tmpNew 'This resets the Total days used
tmpRemainingAH = doc.RemainingAH(0) ' This is the number of days remaining
tmpRemain = tmpTotal + tmpRemainingAH ' This adds the number that was subtracted when the leave was approved
doc.RemainingCalc = tmpRemain 'This resets the remainig days to what it was prior to the new leave being approved
doc.RemainingAH = doc.RemaingCalc 'See above
doc.ComputeWithForm True, False
doc.save True, False
Hope this explains what I need the form to do
James
I have it working with the following perhaps you could get more info from the code
If Not doc Is Nothing Then
tmpHolidaysAH = doc.HolidaysAH(0) 'This is the number of days used
tmpTotal = note.NewDaysTotal(0) 'This is the number of new days booked
tmpNew = tmpHolidaysAH - tmpTotal 'This will reset the value removing the value that was added when approved
doc.TotalDaysOffCalc = tmpNew 'This resets the Total days used
tmpRemainingAH = doc.RemainingAH(0) ' This is the number of days remaining
tmpRemain = tmpTotal + tmpRemainingAH ' This adds the number that was subtracted when the leave was approved
doc.RemainingCalc = tmpRemain 'This resets the remainig days to what it was prior to the new leave being approved
doc.RemainingAH = doc.RemaingCalc 'See above
doc.ComputeWithForm True, False
doc.save True, False
Hope this explains what I need the form to do
James
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That is correct
James
James
when you are setting a value like totalsdaysoff
just set it like this
note.totaldaysoff = 0
also... what do u mean works inconsistently, when does it fail... it;s also better to use cint before doing the math.. something like this:
doc.HolidaysAH = cint(doc.HolidaysAH(0)) - cint(doc.TotalDaysOff(0))
doc.RemainingAH = cint(doc.RemainingCalc(0))
Partha