uuthanh,
you should indeed leave the form and use the query as 'platform' for your calculations. To realise this,
(1) build the query with calculated fields using your VBA functions
(2) change the recordsource of the form in Queryname instead of TableName
(3) change the recordsource of the text controls on the form into the query field names
About how to build a query if you are not familiar at all with Access:
- go to query tab
- click 'new'
- select the tables you need in the dialog box; enter 'close'
- drag the fields you need in the form into the grid below
- enter two calculated fields using the VBA functions for Y & Z
- OK!
If the calculations are also used in other forms, reports, exports, further calculations, summations, analysis,... it might be wise to (1) build a query with ID's (for later linking) & (just) the calculations and (2) use this query (+ specific fields from other tables,...) in a second one used the recordsource for your form.
In the following lines, I present an example I quickly worked out based on your information. By the way:I went here one step further & based the calculation of Y & Z on two factors from different tables instead of one 'X'. Hope this didn't confuse you any further.
I don't think it will be necessary, but if you want & drop your e-mail in a post, I can mail it too.
Good luck & drop a line on the forum if it worked all right.
Happy newyear!
Hasse
ps Other readers: Even I've quite some experience, I'm no pro so if I make some crucial mistakes, please don't remain silent
= = = = = = = = = = = = = = = = = = = = = = = = =
TABLES
tblCALLS
ca_IDcall ca_Subject ca_Time ca_IDemployee ca_IDProject
1 Bug 1 30 1 1
2 Bug 1 45 2 1
3 Bug 2 10 1 1
4 Bug 3 15 1 2
tblPROJECTS
pr_IDproject pr_Name
1 Project One
2 Project Two
tblEMPLOYEES
em_IDemployee em_Name em_Wage em_Function
1 John Williams 100 Helpdesk
2 Bill Wates 250 Programmer
Remarks
ID = Autonumber
ca_Time in minutes
MODULE basCALCULATIONS
Option Compare Database
Option Explicit
'Calculation of Y based on X (= calltime & wage)
Public Function fY(calltime as Single, wage as Single)
fY = calltime * wage 'fill in here your own function
End Function
'Calculation of Z based on X (= calltime & wage)
Public Function fZ(calltime as Single, wage as Single)
fZ = calltime * wage * 2 'fill in here your own function
End Function
Query qryNAME
(SQL-view)
SQL = SELECT tblCalls.ca_IDProject, tblCalls.ca_IDcall, tblCalls.ca_IDemployee, tblCalls.ca_Time AS X, fY([ca_Time],[em_Wage]) AS Y, fZ([ca_Time],[em_Wage]) AS Z
FROM tblCalls INNER JOIN tblEmployees ON tblCalls.ca_IDemployee = tblEmployees.em_IDemployee;
(TABLE-view)
ca_IDProject ca_IDcall ca_IDemployee X Y Z
1 1 1 30 3000 6000
1 2 2 45 11250 22500
2 3 1 10 1000 2000
FORM
recordsource = query
= = = = = = = = = = = = = = = = = = = = = = = = =
ps I can't guarantee I'll be here for any further help. I've engaged myself recently in a rescue plan for one of the last unique Lambic beer breweries in Beersel (Belgium) which unfortunately recently closed. It's a very very (!) urgent case as the pub which makes a 2-unity with the brewery is at this very moment for sale. (We're going to look for Beer lovers, companies,... prepared to invest money in the project without the opportunity of expecting a direct financial return... no evident matter these days) Anyway... I hope the information above will help you out!