I am creating a multiuser database in Access 2000, and I wanted to implement an Autonumber for the generation of Transaction numbers, and also for various internal ID's as well. To generate the autonumbers, I modified the code posted by MichaelRed in faq700-184 "Why AutoNumber shouldn't be used in MultiUser databases (And How to ge the Unique Number)". During my testing, I have discovered that I am on occasion getting duplicate numbers. It seems to not be locking the Autonumber table correctly.
First of all, let me state that I am not faulting MichaelRed or his code. On the contrary, I am quite thankful for it, and I'm trying to figure out what I did wrong. Please bear with me, this may get long.
The modifications I have made involve passing the routine a string to let it know which type of Autonumber I need. My modifications start by taking the string and setting some variables:
Dim strBase As String 'the equivalent of his "Basic Data"
Dim strQuery As String 'the equivalent of his "qSelQIMax"
Dim strTable As String 'the equivalent of his "tblNewQINum"
If strType = "Value1" then
strBase = "tblBase1"
strQuery = "qryAuto1"
strTable = "tblAuto1"
else...
End If
I then use these strings in place of the harcoded strings in the code. We had two users generating the same type of autonumber at the same time, stepping through the code. The first user reached the lines:
Set MyDbs = CurrentDb()
...
Set qSelAutoMax = MyDbs.OpenRecordset(strQuery, dbDenyRead)
Set tblNewAutoNum = MyDbs.OpenRecordset(strTable, dbDenyRead)
and everything seemed to be working correctly. He then stopped and waited. When the second user encountered these lines, we expected an error, but got none. Instead they both were looking at the same values.
The way I have this set up, each type of Autonumber that this function generates has it's own tblAuto and qryAuto that it uses for generating autonumbers, so I don't believe the problem is related (directly) to having multiple types of autonumber. My tables are in a shared back-end on the network, and the forms, queries, modules (including this code), etc. are all in a front-end on the users' local machines. I am using DAO 3.6 I believe.
If anybody (MichaelRed or anybody else) can give me some insight into what I'm doing wrong, I would greatly appreciate it.
First of all, let me state that I am not faulting MichaelRed or his code. On the contrary, I am quite thankful for it, and I'm trying to figure out what I did wrong. Please bear with me, this may get long.
The modifications I have made involve passing the routine a string to let it know which type of Autonumber I need. My modifications start by taking the string and setting some variables:
Dim strBase As String 'the equivalent of his "Basic Data"
Dim strQuery As String 'the equivalent of his "qSelQIMax"
Dim strTable As String 'the equivalent of his "tblNewQINum"
If strType = "Value1" then
strBase = "tblBase1"
strQuery = "qryAuto1"
strTable = "tblAuto1"
else...
End If
I then use these strings in place of the harcoded strings in the code. We had two users generating the same type of autonumber at the same time, stepping through the code. The first user reached the lines:
Set MyDbs = CurrentDb()
...
Set qSelAutoMax = MyDbs.OpenRecordset(strQuery, dbDenyRead)
Set tblNewAutoNum = MyDbs.OpenRecordset(strTable, dbDenyRead)
and everything seemed to be working correctly. He then stopped and waited. When the second user encountered these lines, we expected an error, but got none. Instead they both were looking at the same values.
The way I have this set up, each type of Autonumber that this function generates has it's own tblAuto and qryAuto that it uses for generating autonumbers, so I don't believe the problem is related (directly) to having multiple types of autonumber. My tables are in a shared back-end on the network, and the forms, queries, modules (including this code), etc. are all in a front-end on the users' local machines. I am using DAO 3.6 I believe.
If anybody (MichaelRed or anybody else) can give me some insight into what I'm doing wrong, I would greatly appreciate it.