Ok, let's try and start with the basics (as I see them)
Unless you are going to require this check all over the DB, I would put it where you need it now.?
If it is needed all over then I would write something like
Code:
Public Function MaxVisits(lngPersonID As Long, dtVisitDate As Date, Optional intMax As Integer = 3) As Boolean
Dim strCriteria As String
strCriteria = "CMS = " & lngPersonID & " AND TransactionDate = " & Format(dtVisitDate, strcJetDate)
Debug.Print strCriteria
If DCount("*", "Emails", strCriteria) > intMax - 1 Then
MaxVisits = True
End If
End Function
I would expect an ID field to be Long, not String as well?
You would call it with
Code:
If MaxVisits(Me.PersonID, Me.VisitDate) then 'Defaulting to max 3, supply third parameter if max increases.
MSGBOX "Max Visits already reached for date " & Format(Me.VisitDate,"dd/mm/yyyy")
End If
The format string is held in a module, as I always forget the syntax.
Code:
Public Const strcJetDate = "\#mm\/dd\/yyyy\#" 'Needed for dates in queries as Access expects USA format.
Debug output
Code:
CMS = 125521 AND TransactionDate = #07/23/2015#
True
Comment out the Debug.Print when you have the criteria correct
If nothing else, it should get you started.
HTH