DAvg function returning wrong results

Yet you are not using the non working days?
yes I am adding the non working days with the above Function tiraFS, on post 12,
 
No, all that does is calculate them, you have not included that value in the DAvg()?
 
Here's a database with some useful date function. If you want to exclude holidays as well as weekends, populate the holidays table.
 

Attachments

Gasman, I am including it like this :
Code:
Public Function media(dias As Integer) As Double

Dim sd As Integer, d As Date
d = DateAdd("d", -dias, Now())
sd = tiraFS(d)
dias = dias + sd

media = DAvg("[pLast]", "qryCurrent", "dataCot BETWEEN Date() AND DateAdd('d'," & -dias & ", Date())")


End Function


Public Function tiraFS(inicial As Date) As Integer
Dim n As Integer, a As Date

For a = inicial To Date
  If Weekday(a) = 7 Or Weekday(a) = 1 Then n = n + 1
Next
tiraFS = n
End Function

Pat,
Very usefull functions I am sure I will be using them, thanks
 
And as shown previously, that davg is not going to work????😔
 
You are obsessed with using Now() instead of Date() and I guarantee it will cause you issues.
As @Gasman has pointed out you can't use - Dias in your criteria, we already showed you how to correct that.
Code:
Public Function media(dias As Integer) As Double

Dim sd As Integer, d As Date
    d = DateAdd("d", -dias, Date())
    sd = tiraFS(d)
    dias = -1 * (dias + sd)

    media = DAvg("[pLast]", "qryCurrent", "dataCot BETWEEN Date() AND DateAdd('d'," & dias & ", Date())")


End Function
 
WHY do you keep using Now()? We've ALL told you not to. I even gave you a concrete example and yet your code STILL uses Now()!!!!!!!!!!!!!!!!!!
 
WHY do you keep using Now()? We've ALL told you not to. I even gave you a concrete example and yet your code STILL uses Now()!!!!!!!!!!!!!!!!!!

Sorry my fault, I had already chaged it to date(), but I copy/pasted the wrong syntax from a previous text
 

Users who are viewing this thread

Back
Top Bottom