Autonumber Workaround with SQL Server 2005 BE

J

J. Mullenbach

I built a multi-user contacts application as a split Access database
initially and then moved the back end to SQL Server 2005 using an ODBC
connection. I implemented an AutoNumber workaround to avoid primary key
collisions when users attempt to add records at the same time (probably
borrowed from Allen Browne or Albert Kallal?) by setting the default value of
the ContactID field = DMax("ContactID", "tblContacts") + 1 and trapping any
duplicate key errors as follows:

Private Sub Form_Error(DataErr As Integer, Response As Integer)
On Error GoTo Err_Form_Error
Response = IncrementField(DataErr)
Exit_Form_Error:
Exit Sub
Err_Form_Error:
MsgBox Err.Description
Resume Exit_Form_Error
End Sub
---------------------------------------------------------------------------------
Function IncrementField(DataErr)
If DataErr = 3022 Then
Me!ContactID = DMax("ContactID", "tblContacts") + 1
IncrementField = acDataErrContinue
End If
End Function

This works well with an Access back end, but no longer works since
connecting to SQL Server 2005. I'm guessing the error returned by ODBC is
different? Is there a better way to manage pk fields in multi-user apps when
working with SQL Server?

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top