DCount For Date And UserId, Data Type Mismatch...

Heatshiver

Registered User.
Local time
Tomorrow, 05:29
Joined
Dec 23, 2011
Messages
263
I am trying to use the following code to check if a UserID and Date have been used together:

If DCount("*", "tblGenSum", "[UserID]=" & Me.UserID & " And [Days]=" & Me.Days) > 0 Then
MsgBox "Day already used."
End If


However, I continue to get a data type mismatch. The UserID is numerical, and Days is a date. Other than that, The UserID on the form initially comes from a different form's value.

Any help would be much appreciated. Thank you!
 
Because Days is a date then you need octothorpes (#) so this:

If DCount("*", "tblGenSum", "[UserID]=" & Me.UserID & " And [Days]=" & Me.Days) > 0 Then

Should be:

If DCount("*", "tblGenSum", "[UserID]=" & Me.UserID & " And [Days]=#" & Me.Days & "#") > 0 Then
 
Thanks Bob. For someone reason though, I still get a data type mismatch.

If I use just the UserID portion, I still get the error. If I use the Days by itself it will assume that the day is available even when it's not...
 
Last edited:
One of the problems was that the UserID is a string, so I changed the code accordingly.

However, for whatever reason, Access still sees available dates as used ones...
 
Thank you for all the help! I went about it a bit differently with a DLookup and this worked:

If DLookup("[UserID]", "tblGenSum", "[UserID]= '" & Me.UserID & "' And [Days]= #" & Me.txtDate & "#") Then
MsgBox "Day already in use."
Else
MsgBox "Day not in use."
End If


What I had failed to realize was that I was trying to check an unbound date box against the database dates, so I needed to include the unbound date box.

Thank you for all the help!
 

Users who are viewing this thread

Back
Top Bottom