OK, well above is just some code that call up a recordset (which is just the query in a way that access can look through it), the recordset is just a copy of your query which is why you would put your query name in the "OpenRecordset" line.
So if it's there (the data is not valid) then the query comes up with one line and if there's not match (the data is valid) then the query will bring up that record. So the query is Null(Good) or not null(Bad). Is this how you've got it set up?
Go into the design view of your form, right click on the field we are checking and go to properties. Got to the "Events" tab and select "OnLostFocus" then click th button on the far right of the field with three dots ie "..."
Then paste this in the code page it brings up:
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("YourQUERYNAME"
If rst.Recordcount = 0 Then
'Data is valid
Else
'Data isn't valid
End If
rst.Close
Set rst = Nothing
This is the code to use if your query works just like I stated in this post. If your query brings up a large list then use the code I posted first.
The first code goes though a large list and looks for your field, and let's you know if it is in there, the second set of code will look at a query and tell you if there are any records.
On a side note, if this field always has to be unique, you could just set it as a Primary Key - or just index it allowing no duplicates. That way Access would check for you.
Kyle :
