J
Jonathan
Hi using Access 2003. I would like to use a generic function to insert a new
record and return the id of the new record. a parameter is the field list and
another is the new values.
Public Function SaveRecordGetNewID(TableName As String, IdField As String,
FieldList As String, Values As String) As Long
The following code snipet triggers an error at the add new line.
With rst
Set .ActiveConnection = conn
.CursorLocation = adUseServer
.CursorType = adOpenDynamic
.LockType = adLockBatchOptimistic
.Source = TableName
.Open
.AddNew FieldList, Values
recordID = .Fields(IdField)
.Close
End With
FieldList = "dbCode,dbvVersion,dbvBuild"
Values = "'xxx',999,0"
The error number is 3265, Item not found in this collection. All 3 fields
exist in the table
If I reduce the field list and values to a single field the error number is
-2147217887, Application-defined or object-defined error.
Changing the cursor location and lock type has not resolved this.
Any ideas or suggestions appreciated
Many thanks,
Jonathan
record and return the id of the new record. a parameter is the field list and
another is the new values.
Public Function SaveRecordGetNewID(TableName As String, IdField As String,
FieldList As String, Values As String) As Long
The following code snipet triggers an error at the add new line.
With rst
Set .ActiveConnection = conn
.CursorLocation = adUseServer
.CursorType = adOpenDynamic
.LockType = adLockBatchOptimistic
.Source = TableName
.Open
.AddNew FieldList, Values
recordID = .Fields(IdField)
.Close
End With
FieldList = "dbCode,dbvVersion,dbvBuild"
Values = "'xxx',999,0"
The error number is 3265, Item not found in this collection. All 3 fields
exist in the table
If I reduce the field list and values to a single field the error number is
-2147217887, Application-defined or object-defined error.
Changing the cursor location and lock type has not resolved this.
Any ideas or suggestions appreciated
Many thanks,
Jonathan