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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Prevent redundant data in SQL database using VB code

Status
Not open for further replies.

rtshort

IS-IT--Management
Feb 28, 2001
878
US
I have a database to keep up with clients. If the client is already in the database, I want to add a number to the #Visits column when they enter their information. Their Phone # is the "primary key" so I need to compare that with the information entered on the form. If the Phone # exists in the database I need the #Visits column to be updated with one added to it. Like

.fields("#Visits").value = .fields("#Visits").value + 1

I'm using a reference to ADO 2.5 to open the connection.
How would I go about comparing the Phone# field in code to see if it already exists.
 
could something like

select count(*) from clientTable where PhoneNo = '12 3456 7890'

and check the value, or

select * from clientTable where PhoneNo = '12 3456 7890'

and check if BOF and EOF are both true (empty recordset) Ben
+61 403 395 052
 
If the Phone # exists in the database I need the #Visits column to be updated with one added to it.

[tt]update MyTable
set NumVisits = NumVisits + 1
where PhoneNum = '12345678' [/tt]

The only disadvantage: this won't add a new record if it doesn't already exist. Robert Bradley
teaser.jpg

 
Thanks and sorry. That was more of a VB question than SQL. I'm trying to use both of them together. I did get the answer to the question though. Thanks to all. I'll stick to sql here in the future. Every day above ground is a GOOD DAY!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top