PhoenixDon
MIS
I wrote a little Access program to allow supervisors input the daily duty status of their employees. Managment wanted a report so everyday they knew how many people were at work.
I have two tables, one is all the people assigned, the other is their duty status. I created an AutoExec macro that runs the code below. My problem, each day a new instance of each person is supposed to be created. The first person to access the database runs the code below. If the date is already found, then it's supposed to skip it. But everyday, every record has duplicate dates. What did I do wrong? (BTW, system dates are set by the network and can not be changed by users.)
Any suggestions appreciated.
Thanks,
Don
[tt]
******************************************
Function StartNewDay()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
strSQL = "SELECT Personnel.*, [Duty Status].[Status Date], [Duty Status].[Duty Status], [Duty Status].Comment " & _
"FROM Personnel " & _
"LEFT JOIN [Duty Status] ON Personnel.ID = [Duty Status].ID " & _
"WHERE [Duty Status].[Status Date]= #" & Date & "#"
Set db = CurrentDb
Set rst = db.OpenRecordset(strSQL)
If rst.RecordCount = 0 Then
rst.Close
strSQL = "INSERT INTO [Duty Status] ( ID, [Status Date] ) " & _
"SELECT Personnel.ID, Date() AS TODAY " & _
"FROM Personnel LEFT JOIN [Duty Status] ON Personnel.ID = [Duty Status].ID"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
MsgBox "OK, everyone has been added for today!", vbExclamation
Else
'DO NOTHING
'MsgBox "Sorry, records for today have already been started!", vbCritical
End If
End Function
[/tt]
I have two tables, one is all the people assigned, the other is their duty status. I created an AutoExec macro that runs the code below. My problem, each day a new instance of each person is supposed to be created. The first person to access the database runs the code below. If the date is already found, then it's supposed to skip it. But everyday, every record has duplicate dates. What did I do wrong? (BTW, system dates are set by the network and can not be changed by users.)
Any suggestions appreciated.
Thanks,
Don
[tt]
******************************************
Function StartNewDay()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
strSQL = "SELECT Personnel.*, [Duty Status].[Status Date], [Duty Status].[Duty Status], [Duty Status].Comment " & _
"FROM Personnel " & _
"LEFT JOIN [Duty Status] ON Personnel.ID = [Duty Status].ID " & _
"WHERE [Duty Status].[Status Date]= #" & Date & "#"
Set db = CurrentDb
Set rst = db.OpenRecordset(strSQL)
If rst.RecordCount = 0 Then
rst.Close
strSQL = "INSERT INTO [Duty Status] ( ID, [Status Date] ) " & _
"SELECT Personnel.ID, Date() AS TODAY " & _
"FROM Personnel LEFT JOIN [Duty Status] ON Personnel.ID = [Duty Status].ID"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
MsgBox "OK, everyone has been added for today!", vbExclamation
Else
'DO NOTHING
'MsgBox "Sorry, records for today have already been started!", vbCritical
End If
End Function
[/tt]