Creating a discount function (1 Viewer)

O

Ozchic

Guest
I am trying to createa discount function in a standard module.

The discount is to give people ten percent off selling price.

so far I have written
Function Discount()
Discount = Selling_price*0.9

End Function

This unfortunately is giving me a null value.

if I remove Selling_Price
the value returned on my form is 0.9

debugging is telling me that Selling_Price is empty.

what does this mean?

Your assistance is appreciated.
 

WayneRyan

AWF VIP
Local time
Today, 06:28
Joined
Nov 19, 2002
Messages
7,122
Oz,

Code:
Function DiscountPrice (RetailPrice As Currency) As Currency
   DiscountPrice = RetailPrice * 0.9
End Function

When you call it:

Me.CustomerPrice = DiscountPrice(Me.RetailPrice)

Wayne
 
O

Ozchic

Guest
okay Im a bit confused thankyou for your patience.
I am using Access xp

I am trying to create a discount function

on my form I have a txt box called Selling_Price this displays my selling price the control source is selling price field of the products table.

I have written
Function Discount()
Discount = Selling_Price*0.9

End Function

On my form i have a txtdiscount which will display the discounted amount

I have sub procedure that relates to this txt box

subProcedureUpdateDiscount()
txtDiscount.Value = Discount

End sub

so far my txtdiscount box is empty..
it relates to the functiondiscount as if I type
the function as

FunctionDsicount()
Discount= 0.9
end function
then 0.9 will dsiplay in the txtdiscount

so I am somewhat confused how do I get the function to get the value from the seeling_price text box
or field?

is my function just written incorrrectly?

:confused:
 

WayneRyan

AWF VIP
Local time
Today, 06:28
Joined
Nov 19, 2002
Messages
7,122
Oz,

Don't know exactly what you're saying. I attached a very
small example of a form calling a function to update a
textbox.

Give it a look.

hth,
Wayne
 

Attachments

  • demofunction.zip
    21.4 KB · Views: 254
O

orduck

Guest
ozchic,
Your
Function Discount()
Discount = Selling_Price*0.9
End Function

Will work if you change it to;

Function Discount(ByVal mynumber)
Discount = Forms![YOUR_FORM]![selling_price] * .9
End Function

When you save the function, be sure not to name is Discount!
Name it DiscountPrice or PriceDiscount. Anything but Discount.
In your textbox open the expression builder in control source.
Click on "functions" then the name of your dbm. A list of the functions will be listed. Click on the "discountPrice" (or whatever you named it.) and then in the white box click on "mynumber" in the "discountprice(<mynumber>)" and change <mynumber> to [Selling_price]
click OK.
Open the form and your discount price should be shown in the textbox.
Jim
 
O

orduck

Guest
oz,
Since you are referencing the selling_price in the function all you need is
Function Discount()
you don't need the "Byval mynumber"
jim
 
R

Rich

Guest
Why not just use a query, or type the calculation directly into a control?
 

Users who are viewing this thread

Top Bottom