checking for values in a query

  • Thread starter Thread starter Algo
  • Start date Start date
A

Algo

I have a form that has a phone number field. Upon trying to leave the field
I would like to run a piece of code that would check if the value exists in
a query that I have. If it does then do nothing. If it doesn't then it
should stay in the field and/or give an alert box. Any help is appreciated
 
You can use the DCount() function to see if a row in the Query has the
matching tel. number. Assuming the tel. number is text, something like:

If DCount("*", "YourQuery", "[TelNo] = '" & Me.txtTelNo & "'") = 0 Then
' Your code for "not found"
End If.

You probably need to use the BeforeUpdate Event if you want to keep the
Focus (in case of "not found") on the TextBox txtTelNo.
 
Thanks I'll try that

Van T. Dinh said:
You can use the DCount() function to see if a row in the Query has the
matching tel. number. Assuming the tel. number is text, something like:

If DCount("*", "YourQuery", "[TelNo] = '" & Me.txtTelNo & "'") = 0 Then
' Your code for "not found"
End If.

You probably need to use the BeforeUpdate Event if you want to keep the
Focus (in case of "not found") on the TextBox txtTelNo.

--
HTH
Van T. Dinh
MVP (Access)



Algo said:
I have a form that has a phone number field. Upon trying to leave the field
I would like to run a piece of code that would check if the value exists in
a query that I have. If it does then do nothing. If it doesn't then it
should stay in the field and/or give an alert box. Any help is appreciated
 
Back
Top