standard module-public function (1 Viewer)

pizaccess

New member
Local time
Today, 12:11
Joined
Dec 24, 2001
Messages
8
I'm trying to create a standard module with a public function. The function is a simple calculation that returns a value to a text box called "Total". I'm having a hard time creating the module.
The function is:
=[DeliveryPrice]+[Express]+[Waiting/Downtime]+[LiftGate]+[InsideDelivery]+[ConventionCharges]+[TwoMan]+[FuelSirCharge]

This is what I put in as the control source for the text box "Total"

Can you help me with the process of putting this into a standard module. Everything I've tried does not work. Do I attach this to an event and how then is this global so the text box value can be used on a report.

Thank you for any assistance
Patrick
 

raindrop3

Registered User.
Local time
Today, 12:11
Joined
Sep 6, 2001
Messages
98
Hello,

The datatype of the fields must be defined as 'number' in the table. Then in the control source of the 'Total' field type the following:

=[DeliveryPrice]+[Express]+[Waiting/Downtime]+[LiftGate]+[InsideDelivery]+[ConventionCharges]+[TwoMan]+[FuelSirCharge]

This works if all the fields are on the same form. If they aren't on the same form, you can use this statement:

=[DeliveryPrice]+[Express]+[Waiting/Downtime]+[LiftGate]+[InsideDelivery]+[ConventionCharges]+[TwoMan]+[FuelSirCharge+[Forms]![YourForm]![Yourfield]

(In this case the last field is on another form)

You don't need to put it in a module. If you want to put it in a module, do something like this:

global counttotal as number
counttotal = [forms]![YourForm]![YourControl]+[Forms]![YourForm]![Yourfield2]+[Forms]![YourForm]![Yourfield3]etc.

In a event of the form on which the total is you place the following code.

total = counttotal

For more help, I'am back tomorrow (friday). GT + 1.

Greetings,

Albert

[This message has been edited by raindrop3 (edited 01-10-2002).]
 

pizaccess

New member
Local time
Today, 12:11
Joined
Dec 24, 2001
Messages
8
I'm still a little unclear. I'm trying to put this in a global module so the value can be used in a report. Because it is a calculated field it does not have a control source from a table so it has to be placed in a module right?
Can these be currency fields in my table instead of number.

Option Compare Database
Option Explicit

Public Function conttotal() As Integer

counttotal = [sfrmCharges]![DeliveryPrice] + [sfrmCharges]![Express] + [sfrmCharges]![Waiting/Downtime] + [sfrmCharges]![LiftGate] + [sfrmCharges]![InsideDelivery] + [sfrmCharges]![ConventionCharges] + [sfrmCharges]![TwoMan] + [sfrmCharges]![FuelSirCharge]
counttotal = Total

End Function

here's what I wrote out. I still don't have a very good understanding of vba. Im not sure what you meant when you said "your control". Can you look at what I have written and tell me how to fix it so it works
 
R

Rich

Guest
Why can't you use a query or a calculated control?

[This message has been edited by Rich (edited 01-11-2002).]
 

raindrop3

Registered User.
Local time
Today, 12:11
Joined
Sep 6, 2001
Messages
98
Hello,

Your control MUST BE Your field5 or 6. Sorry, my mistake.

If a field you use is on another form, you had to refer to that form. Forms! means: it is on a form. forms![YourFormName] means: It is on a form with the name [YourFormName].
Forms![YourFormName]![YourFieldToIncludeInCalculation] says: Use [YourFieldToIncludeInCalculation] on the form with the name [YourFormName]

Hope this helps.

Consider the suggestion of Rich!

Albert

[This message has been edited by raindrop3 (edited 01-11-2002).]
 

pizaccess

New member
Local time
Today, 12:11
Joined
Dec 24, 2001
Messages
8
I know I'm probably responding to this too late, but I hope possibly Rich might still read this. In response to your question, I can't use a calculated control because I'm trying to pass this value in the "Total" text box on to a report and it is my understanding that the only way to do this is by creating a standard module. I thought it would be fairly simple to create this module however I STILL am unable to create it. My VBA knowledge is not the greatest so I figured somebody out there with expertise could help.
If anyone has any suggestions as to the module or a different route to take as far as passing this value through without having the form open please respond,
Thanks,
Patrick
 
R

Rich

Guest
Since the report has the underlying data you can use the same calculated control on the report.
 

Users who are viewing this thread

Top Bottom