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!

Capturing query results to perform another function

Status
Not open for further replies.

Dbless

IS-IT--Management
May 8, 2002
22
US
Trying to populate a table with an sql update statement from VB code and if the record is not there I want to execute a separate query to insert the new record. How do I know that the first (update) query resulted in 0 records updated to determine if I need to run the insert statement.

Any suggestions would help. Thanks
 
Drop in another query that counts the rows in the target table after the 1st query runs...something like:

SELECT Count(*) AS RowCount FROM <table>

If RowCount = 0, you know the 1st query didn't add any records.
 
If you show us the code you're using we'll be able to give you more detailed responses, but...

Do you know about the RecordsAffected property? After you execute a sql statement, this property of the database variable you're using will tell you how many records were affected. You could have an if structure based on the value of this property.

Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995

Take a look at the Developer's section of the site for some helpful fundamentals.
 
Thanks the recordseffected property works great with the querydef.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top