M
mlm198
Hi,
I have two tables, the main table which contains a list of names and
total absences and the other which contains some names and absence
dates. What I want to do is automatically count the number of absences
there were for each name in the past 30 days. I have the code as
below. The problem is my dates in the absence table are in a British
format (and I want to keep British) but DCount only seems to work with
American dates. Is there anyway I can get DCount to work with british
dates or convert the absence table using format e.g. something like
format([absence], "mm/dd/yy")?
Any help will be greatful.
Matt
Dim var As Integer
Dim namest As String
Dim datedff As Date
Dim InYear As String
Dim InMonth As String
Dim InDay As String
Dim datedff2 As String
Dim Db As DAO.Database
Dim rs As DAO.Recordset
Set Db = CurrentDb
Set rs = Db.OpenRecordset("Employee")
datedff = Date - 30
InYear = Mid(datedff, 9, 2) 'split date for Dcount
InMonth = Mid(datedff, 4, 3)
InDay = Mid(datedff, 1, 3)
datedff2 = InMonth & InDay & InYear 'note date is American format
tets = datedff2
rs.MoveFirst
Do While Not rs.EOF
namest = rs![Name]
var = DCount("[AutoID]", "[absence]", _
"[Name] = '" & namest & _
"' AND [AdEndDate] > #" & datedff2 & "#")
rs.Edit
With rs
rs![Absence30] = var
.Update
End With
rs.MoveNext
Loop
rs.Close
Db.Close
Set rs = Nothing
Set Db = Nothing
Me!Absence30.Requery
I have two tables, the main table which contains a list of names and
total absences and the other which contains some names and absence
dates. What I want to do is automatically count the number of absences
there were for each name in the past 30 days. I have the code as
below. The problem is my dates in the absence table are in a British
format (and I want to keep British) but DCount only seems to work with
American dates. Is there anyway I can get DCount to work with british
dates or convert the absence table using format e.g. something like
format([absence], "mm/dd/yy")?
Any help will be greatful.
Matt
Dim var As Integer
Dim namest As String
Dim datedff As Date
Dim InYear As String
Dim InMonth As String
Dim InDay As String
Dim datedff2 As String
Dim Db As DAO.Database
Dim rs As DAO.Recordset
Set Db = CurrentDb
Set rs = Db.OpenRecordset("Employee")
datedff = Date - 30
InYear = Mid(datedff, 9, 2) 'split date for Dcount
InMonth = Mid(datedff, 4, 3)
InDay = Mid(datedff, 1, 3)
datedff2 = InMonth & InDay & InYear 'note date is American format
tets = datedff2
rs.MoveFirst
Do While Not rs.EOF
namest = rs![Name]
var = DCount("[AutoID]", "[absence]", _
"[Name] = '" & namest & _
"' AND [AdEndDate] > #" & datedff2 & "#")
rs.Edit
With rs
rs![Absence30] = var
.Update
End With
rs.MoveNext
Loop
rs.Close
Db.Close
Set rs = Nothing
Set Db = Nothing
Me!Absence30.Requery