DCount Type Mismatch

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In the Load event of a form that adds notes to a given project, I want to
check if a record already exists for the given Project
Number/StaffID/NoteDate combination. The values of these three fields are
stored in textboxes on the form from which the Notes form is opened. Since
this can be two different forms, the name of the form is passed using
OpenArgs.

The types of the above fields are Text, Integer, and Date/Time,
respectively. The DCount call below crashes with a Type Mismatch error. I'd
appreciate any help.

If DCount("[ProjectNoteID]", "ProjectNotes", _
"[ProjectNumber]=" & "'" &
Forms(Me.OpenArgs).Controls("txtProjectNumber") & "'" & _
" AND [StaffID] = " & Val(Forms(Me.OpenArgs).Controls("txtStaffID"))
& _
" AND [NoteDate] = " & "#" &
Forms(Me.OpenArgs).Controls("txtPeriodStartDate") & "#" + _
Val(Forms(Me.OpenArgs).Controls("txtDayNumber"))) = 0 Then

.... do stuff

Thank you.
Sprinks
 
G'day Sprinks,

What's the + txtDayNumber at the end meant to be achieving? If you are
wanting to add it to the date, it's in the wrong place, and is almost
certainly what's causing your syntax error.

Damian.
 
Damian,

Thank you; that is the error.

Sprinks

Damian S said:
G'day Sprinks,

What's the + txtDayNumber at the end meant to be achieving? If you are
wanting to add it to the date, it's in the wrong place, and is almost
certainly what's causing your syntax error.

Damian.

Sprinks said:
In the Load event of a form that adds notes to a given project, I want to
check if a record already exists for the given Project
Number/StaffID/NoteDate combination. The values of these three fields are
stored in textboxes on the form from which the Notes form is opened. Since
this can be two different forms, the name of the form is passed using
OpenArgs.

The types of the above fields are Text, Integer, and Date/Time,
respectively. The DCount call below crashes with a Type Mismatch error. I'd
appreciate any help.

If DCount("[ProjectNoteID]", "ProjectNotes", _
"[ProjectNumber]=" & "'" &
Forms(Me.OpenArgs).Controls("txtProjectNumber") & "'" & _
" AND [StaffID] = " & Val(Forms(Me.OpenArgs).Controls("txtStaffID"))
& _
" AND [NoteDate] = " & "#" &
Forms(Me.OpenArgs).Controls("txtPeriodStartDate") & "#" + _
Val(Forms(Me.OpenArgs).Controls("txtDayNumber"))) = 0 Then

.... do stuff

Thank you.
Sprinks
 
Back
Top