asked on
Function InsertRecord(FirstName As String, LastName As String) As Long
Dim cn As ADODB.Connection
Dim cmd As New ADODB.Command
Dim rs As New ADODB.Recordset
Set cn = CurrentProject.Connection
With cmd
Set .ActiveConnection = cn
.CommandType = adCmdText
.CommandText = "Insert INTO Employees(Lastname, FirstName) Values('" & LastName & "', '" & FirstName & "')"
.Execute
rs.Open "Select @@Identity as NewID", cn, Options:=adCmdText
InsertRecord = rs("NewID")
End With
End Function
ASKER
Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.
TRUSTED BY
if you have an Access front end linked to SQL back end then you need to create a "pass through" query to SQL in order to use @@IDENTITY.
An Access query to linked tables in SQL will not work here.