Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validation in a form

Status
Not open for further replies.

Paulfitzg1

Technical User
Jul 7, 2003
11
IE
I have set up a customer details form in access 2000. The first entry is a CustID. When an entry is made here I want the form to check the customers.CustID table to see if the entry already exists so that the user will know this before entering lots of customer data.

I have been trying to set up a validation rule but don't seem to be getting anywhere.

Any help here would be apprectaied.
 
you can use some code...

dim DB as database
dim RS as recordset
dim sSQL as string

set db=currentdb
ssql="SELECT CustID FROM customers " & _
"WHERE CustID = " & CustID
set rs=db.openrecordset(ssql)
if not rs.eof then
rs.movelast
rs.movefirst
end if

if rs.recordcount>1 then
Here you can display a message saying that the
customer already exist
endif

rs.close
db.close
set rs=nothing
set db=nothing

Another way to do that eith less programming, is to set CustID to unique key, so it can't be duplicate. If the user try to add a similar value an error will be raised. You just have to catch this error number and display a message saying that the customer already exist...

Mal'chik [bigglasses]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top