Hello
I'm having trouble with the format of Dates for an attendance form, VBA script and tables in Access 2010. I have a form to record attendance. When a user clicks the check box beside a persons name, it inserts the current date into a table called tblMadAttend.
The problem I'm having is with the format of the date when it gets inserted into the table. For the first 12 days of January, the date format was 01/02/2015, 01/05/2015, 01/08/2015, 01/09/2015, 01/12/2015. For January 13th, the date format in the table was
13/01/2015.
I've tried formatting the date using the command Format(Date, "mm/dd/yyyy") but it still inserts the date as 13/01/2015 and 14/01/2015. I've tried to set the Table field to format Short Date with an input mask of 00/00/0000 and removed the format. I've also
played with my system date settings which switched the first 12 dates to 02/01/2015, 05/01/2015, 08/01/2015, 09/01/2015 and 12/01/2015. The date for the 13th changed to 01/13/2015.
The form also checks to see if the person has been marked present or not, and if they have been marked present for the current date, it checks the check box. The problem is the different date formats don't always match.
The code I have is as follows.
Option Compare Database
Dim sqlStr As String
Dim Msg, Style, Response
Private Sub cmdAttend_Click()
If (IsNull(DLookup("[ID]", "tblMadAttend", "[PID]='" & Me.txtID.Value & "' and [AttDate]=#" & Date & "#"))) Then
Me.chkAttend.Value = True
sqlStr = "INSERT into tblMadAttend(PID, AttDate) VALUES('" & Me.txtID.Value & "', #" & Date & "#)"
CurrentDb.Execute sqlStr, dbFailOnError
Else
Msg = "This person has been recorded present already for today. Do you want to make them absent?"
Style = vbYesNo + vbCritical + vbDefaultButton2
Response = MsgBox(Msg, Style)
If Response = vbYes Then
sqlStr = "DELETE from tblMadAttend WHERE [PID]='" & Me.txtID.Value & "' and [AttDate]=#" & Date & "#"
CurrentDb.Execute sqlStr, dbFailOnError
MsgBox "Record Deleted"
Me.chkAttend.Value = False
End If
End If
End Sub
Private Sub Form_Load()
Dim rcount As Integer
Dim i As Integer
rcount = DCount("ID", "qryMadAttendance1")
For i = 1 To rcount
If (IsNull(DLookup("[ID]", "tblMadAttend", "[PID]='" & Me.txtID.Value & "' and [AttDate]=#" & Date & "#"))) Then
Me.chkAttend.Value = False
Else
Me.chkAttend.Value = True
End If
DoCmd.GoToRecord , , acNext
Next i
DoCmd.GoToRecord , , acFirst
End Sub
I've tried everything I can think of to get a date format of dd/mm/yyyy but for some reason the first 12 days of the month are seeing the 01 as the day instead of the month.
Any help would be very much appreciated.
Thanks,
Ryan Doyle