Re: autonumber
- From: "Veign" <NOSPAMinveign@xxxxxxxxx>
- Date: Tue, 16 Aug 2005 13:54:35 -0400
Why do you need to know the AutoNumber before the adding of the record?
You can find out what the last AutoNumber value was by using the SELECT
@@Identity statement. This will return the autonumber value of the last
entered record...
'-----------------------Start Code------------------------------
Dim RS As Recordset
Dim CNN As Connection
Set CNN = New Connection
Set RS = New Recordset
'Build SQL Statement
Dim strSQL
strSQL = "INSERT INTO Customer (Name) " & _
"VALUES ('(Customer1)')"
With CNN
.Open ConnectionString
.Execute strSQL
'Get the assigned autonumber
Dim lngID As Long
Set RS = .Execute("SELECT @@Identity FROM Customer")
lngID = RS.Fields(0).Value
If RS.State = adStateOpen Then RS.Close
Set RS = Nothing
.Close
End With
Set CNN = Nothing
'---------------------------------------------------------------------
--
Chris Hanscom - Microsoft MVP (VB)
Veign's Resource Center
http://www.veign.com/vrc_main.asp
--
"Dan P" <dp55@xxxxxxxxx> wrote in message
news:el%23qybooFHA.2156@xxxxxxxxxxxxxxxxxxxxxxx
> rs.addnew will assign an autonumber for you.
>
> Is there a way to know what the next autonumber to be assigned will be
> before the rs.addnew by using a command instead of something like
> rs.movelast
>
>
> VB and ADO/Access 97 database
> Thanks
>
>
.
- Follow-Ups:
- Re: autonumber
- From: Dan P
- Re: autonumber
- References:
- autonumber
- From: Dan P
- autonumber
- Prev by Date: autonumber
- Next by Date: Modify crosstab query via VBA
- Previous by thread: autonumber
- Next by thread: Re: autonumber
- Index(es):
Relevant Pages
|