VBA code to divide numbers for percentages - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

VBA code to divide numbers for percentages

dbaldwindbaldwin Posts: 2Member
I'm using Access 2007. I have VBA code that takes a budget amount as a currency veriable and subtracts from it a sum of expenditure YTD currency variable, which works fine resulting with a budget balance remaining. I tried adding code to divide the sum variable by the budget variable, but the percent that is returned is 0.00% My table fields are currency and the form field is formated to percent. Any help to return the actual percent would be greatly appreciated.

[code]Private Sub cmdOpenBalance_Click()
DoCmd.SetWarnings False
DoCmd.OpenQuery "qryExpendStnd"
DoCmd.SetWarnings True
Dim strHoldYear As String
Dim curHoldRent As Currency
Dim curHoldFurn As Currency
Dim curHoldSecD As Currency
Dim curHoldRehb As Currency
Dim curHoldCont As Currency
Dim curSumRent As Currency
Dim curSumFurn As Currency
Dim curSumSecD As Currency
Dim curSumRehb As Currency
Dim curSumCont As Currency
DoCmd.OpenForm "frmBudget"
strHoldYear = Forms![frmBudget]![BudgetYear]
curHoldRent = Forms![frmBudget]![RentStipends]
curHoldFurn = Forms![frmBudget]![FurnitureHoushld]
curHoldSecD = Forms![frmBudget]![SecDeposit]
curHoldRehb = Forms![frmBudget]![Rehab]
curHoldCont = Forms![frmBudget]![Contingency]
DoCmd.Close acForm, "frmBudget"
DoCmd.OpenForm "frmSumRent"
curSumRent = Forms![frmSumRent]![SumOfAmount1]
DoCmd.Close acForm, "frmSumRent"
DoCmd.OpenForm "frmSumFurnHoushld"
curSumFurn = Forms![frmSumFurnHoushld]![SumOfAmount1]
DoCmd.Close acForm, "frmSumFurnHoushld"
DoCmd.OpenForm "frmSumSecDep"
curSumSecD = Forms![frmSumSecDep]![SumOfAmount1]
DoCmd.Close acForm, "frmSumSecDep"
DoCmd.OpenForm "frmSumRehab"
curSumRehb = Forms![frmSumRehab]![SumOfAmount1]
DoCmd.Close acForm, "frmSumRehab"
DoCmd.OpenForm "frmSumContin"
curSumCont = Forms![frmSumContin]![SumOfAmount1]
DoCmd.Close acForm, "frmSumContin"
DoCmd.OpenForm "frmBalance"
Forms![frmBalance]![BudgetYear] = strHoldYear
Forms![frmBalance]![RentStipends] = curHoldRent - curSumRent
Forms![frmBalance]![RentPercent] = curSumRent / curHoldRent
Forms![frmBalance]![FurnitureHoushld] = curHoldFurn - curSumFurn
Forms![frmBalance]![FurnPercent] = curSumFurn / curHoldFurn
Forms![frmBalance]![SecDeposit] = curHoldSecD - curSumSecD
Forms![frmBalance]![SecDPercent] = curSumSecD / curHoldSecD
Forms![frmBalance]![Rehab] = curHoldRehb - curSumRehb
Forms![frmBalance]![RehPercent] = curSumRehb / curHoldRehb
Forms![frmBalance]![Contingency] = curHoldCont - curSumCont
Forms![frmBalance]![ContinPercent] = curSumCont / curHoldCont


End Sub[/code]
Sign In or Register to comment.