You could use the DCount function for this. If it returns 1 or more, the
date is invalid. In the control's BeforeUpdate event, try the following:
If DCount("[DateField]", "[TableName]", "[DateField]=#" & Me.txtDateTextBox
& "#") >= 1 Then
MsgBox "Invalid Date"
Cancel = True
Me.txtDateTextBox .SelStart = 0
Me.txtDateTextBox .SelLength = Len(Me.txtDateTextBox .Text)
End If
The last 2 lines just cause the invalid date to be highlighted so that the
user doesn't have to delete it before they can enter another date. The
brackets [] aren't necessary unless there are spaces in the names or a
reserved word is used for the name, but they shouldn't hurt anything if you
use them anyway.
--
Wayne Morgan
MS Access MVP
"Katherine" <(E-Mail Removed)> wrote in message
news:21D22273-158A-4DF8-BD38-(E-Mail Removed)...
> I'm completely new to coding in VB and I'm making a database. I am
starting to pick up a few things and am hoping someone can teach me
something new here.
>
> I have a text box in which the date is entered after it has been picked on
a drop down calendar. Before the user moves off from the date text box, I
want to runa query that checks if the date entered is a valid date by
comparing it to a table of invalid dates. If it finds a match in the query,
I want to code it so that an error box pops up and says "Invalid date, pick
another" and, if the query produces no matches, I want the user to just be
able to continue entering the record as per usual. Please help

>