C
cwh060
Hi there, I’m not great as a developer, but I have a small timesheet
application developed in Access (2000). I am trying to use Dcount in the
Before Update to warn a user if they have input a duplicate timesheet. The
tbl_Main is quite simple, it has three columns. A primary key, Text input
field and Date/Time input field.
The code works if I use either the text field (Chris) or the Week Ending Date
field (14-Nov-08) but not together using an AND expression. I know it’s
probably because I am comparing a text field to a date field but for the life
of me, I can’t figure this out.
I have searched through the forum for answers, I find a variety of questions,
but nothing seems to overcome my simple error of “Type Mismatchâ€.
Any help would be appreciated. I've tried all sorts of different format
combinations on the date field but nothing has worked so far.
Thanks
cwh060
tbl_Main looks like this.
RecordID Staff Member Week Ending Date
100 Chris 14-Nov-08
My code looks like this:
Private Sub Form_BeforeUpdate(Cancel As Integer)
sName = "[Staff Member]= '" & Me.Combo4 & "' "
sWeek = Format(Me.[Combo6], ("dd\/mm\/yy" & ""))
If DCount("*", "tbl_Main", sName And sWeek) > 0 Then
MsgBox "This is a duplicate Record", vbOKCancel
Me.Undo
Else
End If
End Sub
application developed in Access (2000). I am trying to use Dcount in the
Before Update to warn a user if they have input a duplicate timesheet. The
tbl_Main is quite simple, it has three columns. A primary key, Text input
field and Date/Time input field.
The code works if I use either the text field (Chris) or the Week Ending Date
field (14-Nov-08) but not together using an AND expression. I know it’s
probably because I am comparing a text field to a date field but for the life
of me, I can’t figure this out.
I have searched through the forum for answers, I find a variety of questions,
but nothing seems to overcome my simple error of “Type Mismatchâ€.
Any help would be appreciated. I've tried all sorts of different format
combinations on the date field but nothing has worked so far.
Thanks
cwh060
tbl_Main looks like this.
RecordID Staff Member Week Ending Date
100 Chris 14-Nov-08
My code looks like this:
Private Sub Form_BeforeUpdate(Cancel As Integer)
sName = "[Staff Member]= '" & Me.Combo4 & "' "
sWeek = Format(Me.[Combo6], ("dd\/mm\/yy" & ""))
If DCount("*", "tbl_Main", sName And sWeek) > 0 Then
MsgBox "This is a duplicate Record", vbOKCancel
Me.Undo
Else
End If
End Sub