Hi Chris ,
You can use the AddNew method of a recordset, insert a new record and the get its ID. To make this work, the Id column for the Coupon should be set to Autonumber. The following (untested) code should gie you an idea.
Code:
Dim rsCoupon
Set rsCoupon = Server.CreateObject("ADODB.Recordset")
rsCoupon.Open "SELECT * FROM Coupon WHERE Id = -1", myConnection
rsCoupon.AddNew()
rsCoupon.Update()
Dim myNewCouponId
myNewCouponId = rsCoupon("Id")
This code opens an empty recordset. Since you don't need previous records, I use WHERE Id = -1 to make sure no useless records are returned. Although you get no records, you do get the meta data, so you can call AddNew. If you then call Update, the record is inserted in the database, and you can get the ID of the newly created record by querying the Id column. Since Id is an autonumber, you can be sure no other user gets the same ID.
Once you have to ID in the myNewCouponId variable, you can do with it whatever you want, like insert it in the current user's record.
Hope this helps,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of
ASP.NET 2.0 Instant Results and
Beginning Dreamweaver MX / MX 2004
While typing this post, I was listening to:
Wherever I May Roam by
Metallica (Track 5 from the album:
Metallica)
What's This?