db.Execute result

MnInShdw
MnInShdw used Ask the Experts™
on
I'm using the following to insert a record in a table:
sql="INSERT INTO table (Order,Quantity) VALUES ('test',10)
db.execute (sql)

Open in new window


How can I find out the db.execute actually added a new record or not.

If the order field's Index is set to Yes(No Duplicate)
it will fail to insert a new record if Order is duplicated




thanks for any kind of help
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Database Architect / Application Developer
Top Expert 2007
Commented:

Dim lRecs As Long

sql="INSERT INTO table (Order,Quantity) VALUES ('test',10)
With CurrentDb
 .execute (sql)
lRecs = .RecordsAffected
End With

If lRecs>0 then ' it happened

mx
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
Top Expert 2007
Commented:
From more information, look up the RecordsAffected Property in VBA Help.

Basically:

"Returns the number of records affected by the most recently invoked Execute method."

mx

Author

Commented:
Million thanks
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
Top Expert 2007

Commented:
you are welcome.

mx

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial