Function explanation (1 Viewer)

tblues87

Registered User.
Local time
Today, 09:16
Joined
Apr 7, 2011
Messages
22
Can someone please explain me how does function work with object in some form.
I've been reading VBA books but I can't figure it out. I was working with functions and loops in c++ but I just can't with VBA and Access 2007.

I need this.

I have form from tblPaying in which are fields PayingMathod and Price. I want to write a function that returns value of Price.
Example:
if in field PayingMethods is written "Credit Card"
then in field Price should be 1000$

And please if someone write a code can he/she explain it.

Thank you
 
You have provided very little information for a whole function to be written.

Where's the data coming from? What fields of data need to be checked, just the PayingMethods field? What are the options available? Where is it returning the value to, a control on a form / report or a field in a query?

etc...
 
Thanks for fast answer

the tblPaying has 2 fields: PayingMethod, Price and also on form there are two same objects. field PayingMethod is lookup column that has: Cash, Cash on credit, Credit card, credit card on credit
For each of these paying methods the price is different.

The function should return value to control on form
 
You could create a simple lookup table with the payment methods and the amounts.

That way all you would need to do is use DLookup and .requery to update the control holding the amount.
 
OK I can do that, but can you please write a code for what I'm asking because I want to learn how to do that and I's driving me crazy.

thanks
 
You shouldn't technically need a function, in Access you can create a sub tied to events on controls.

You can use something like the following on the after update event of the PaymentMethod:

Code:
If txtPaymentMethod = "Credit card" then
   txtAmount = "£1000"
ElseIf txtPaymentMethod = "Cash" then
   txtAmount = "£500"
End If
 

Users who are viewing this thread

Back
Top Bottom