JMongi
Active member
- Local time
- Today, 02:42
- Joined
- Jan 6, 2021
- Messages
- 802
Defining a DAO database object, string variable and long variableDim db As DAO.Database
Dim strSQL As String
Dim lngNewID As Long
Creating/assigning an instance based on the current db.Set db = CurrentDb()
Setting the string of the SQL commandstrSQL = "INSERT INTO tblDrawings(Description) VALUES('Sample Drawing')"
Executing the SQL string with a setting about handling error messages I believe.With db
.Execute strSQL, dbFailOnError
Assigning a number ID to the variable.lngNewID = .OpenRecordset("SELECT @@IDENTITY")(0)
End With
So, what is the syntax of the @@IDENTITY portion. I must not recognize the syntax of the VBA .OpenRecordset. I recognize the SELECT @@IDENTITY from the tutorial but not how it is actually being implemented.
Demoing the use of the shiny new ID.MsgBox "One new record was added to tblDrawings with the assigned new ID of " & lngNewID, vbInformation, "Done!"
Closing the recordset.Set db = Nothing
So, would this still work with SQL server? I've seen the db.execute methodology as well as the DoCmd.RunSQL methodology. Is one more compatible with migrating to SQL server than the other?