checking for values in a query

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
 
V

Van T. Dinh

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.
 
A

Algo

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top