[Solved] Text boxes in Base form with their values tallied
Posted: Fri Mar 01, 2019 1:53 am
First off i'm a senior citizen with limited computer knowledge. I have been able to set up a database table and a form associated to it. On this form i have 3 text boxes assigned for dollar amounts to be entered. Is it possible to have the 3 box values tallied and displayed into a 4th text box via a button using a Macro. The first text box(Amount) will always be filled with a dollar amount and the next 2 (Shipping Cost) & (Fees) may or may not have a dollar amount entered. The 4th box would be labeled NetProfit so i would like to have (Shipping Cost) & (Fees) subtracted from Amount for the net profit value.
This is the code I've written thus far with not knowing if it is even close to what i need for a Macro. so any help or direction would be greatly appreciated. Thanking you in advance for any consideration.
This is the code I've written thus far with not knowing if it is even close to what i need for a Macro. so any help or direction would be greatly appreciated. Thanking you in advance for any consideration.
Code: Select all
Option Explicit
Sub CalculateNetProfit
Dim oForm As Object
Dim oColumns As Object
Dim dAmount As Double
Dim dShippingCost As Double
Dim dFees As Double
Dim dBaseNetProfit As Double
Rem Gets Main internal form
oForm = ThisComponent.Drawpage.Forms.getByName(“MainForm”) ‘Get Form
Rem Check if textboxes have value
dAmount = oForm.getByName(“Amount”).getCurrentvalue()
dShippingCost = oForm.getByName(“Shipping Cost”).getCurrentValue()
dFees = oForm.getByName(“Fees”).getCurrentValue()
Rem Initial netprofit
dBaseNetProfit = 0.00
Rem Add NetProfit if value
if dAmount Then
dBaseNetProfit = dBaseAmount
End if
if dShippingCost Then
dBaseNetProfit = dBaseAmount – dBaseShippingCost
Else
dBaseNetProfit = dBaseAmount
End if
if dFees Then
dBaseNetProfit = dBaseAmount - dbaseShippingCost – dBaseFees
Else
dBaseNetProfit = dBaseAmount
End if
Rem Obtain and update NetProfit
oColumns = oForm.getColumns()
oColumns.getByName(“NetProfit”).updateDouble(dBaseNetProfit)
End Sub