Function Select Sum (1 Viewer)

sargon

Registered User.
Local time
Today, 08:11
Joined
Mar 13, 2006
Messages
30
I have:

1) Table1 containing fields: ID, Name, Wage, WorkingHours, Date,
2) Form1 containing: txtDate, txtCO

I must create a Function that Sum the Wage from last 5 days.

Exp1 = DSUM([Wage],[Table1],Where Date <[Forms]![Form1]![txtDate]-5)

But I must do it in SQL (VBA).

I can't undesternd how to VBA...


Code:
Function WA(CO) As Integer

Dim db As DAO.Database
Dim rs As DAO.Recordset

Dim strSQL As String
Set db = CurrentDb

If CO>0 Then

strSQL = "SELECT Sum(Wage) AS [SumOfWage] FROM [Table1] WHERE Date < Forms![Form1]![txtData]-5

Set rs = db.OpenRecordset(strSQL)

    WA= rsTot("SumOfWage")

rs.Close
db.Close
Set db = Nothing

Else 

WA = 0

EndIf

Exit Function
 

sargon

Registered User.
Local time
Today, 08:11
Joined
Mar 13, 2006
Messages
30
I dont know how to put into a variable the result of an SQL...
 

mdow

Registered User.
Local time
Today, 01:11
Joined
Apr 13, 2006
Messages
12
Set rs = db.OpenRecordset(strSQL, dbOpenSnapshot)

WA= rs![SumOfWage]
 

Users who are viewing this thread

Top Bottom