How to check to a query field when input a value?

  • Thread starter Thread starter Gary
  • Start date Start date
G

Gary

Hi,

When I input in a form field , if I want system can check is it have the
same record in a query,
if no, show a message box.

Please help, thank!

Gary
 
Gary,

Here's one idea, for code on the Before Update event of the control on
the form...

If DCount("*","YrQuery","[YrField]='" & Me.YrField & "'") = 0 Then
MsgBox "YourMessage"
Cancel = True
End If

This example assumes a text data type. If it's a number, the code is
like...

If DCount("*","YrQuery","[YrField]=" & Me.YrField) = 0 Then
MsgBox "YourMessage"
Cancel = True
End If
 
Thank so much!!

Steve Schapel said:
Gary,

Here's one idea, for code on the Before Update event of the control on
the form...

If DCount("*","YrQuery","[YrField]='" & Me.YrField & "'") = 0 Then
MsgBox "YourMessage"
Cancel = True
End If

This example assumes a text data type. If it's a number, the code is
like...

If DCount("*","YrQuery","[YrField]=" & Me.YrField) = 0 Then
MsgBox "YourMessage"
Cancel = True
End If

--
Steve Schapel, Microsoft Access MVP

Hi,

When I input in a form field , if I want system can check is it have the
same record in a query,
if no, show a message box.

Please help, thank!

Gary
 
Back
Top