Create Unique Id
Im manually creating a League id for new leagues in my site(Cant use autonumber). The problem is when i get to league 11, i get the following error:
Microsoft JET Database Engine error '80040e21'
The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again.
The League type is "Text" in access.
Here is my code:
dim strMemberId, dblMemberId
if (rsUsers.BOF) AND (rsUsers.EOF) Then
strMemberId = 1
else
rsUsers.MoveLast
strMemberId = rsUsers("MemberId")
If CDbl(Right(strMemberId, 2) >= 10) Then
dblMemberId = CDbl(Right(strMemberId, 2))
ElseIf cint(Right(strMemberId, 3)) >= 100 Then
strMemberId = CDbl(Right(strMemberId, 3))
ElseIf cint(Right(strMemberId, 4)) >= 1000 Then
lngMemberId = CDbl(Right(strMemberId, 4))
Else
dblMemberId = CDbl(Right(strMemberId, 1))
End If
dblMemberId = dblMemberId + 1
strMemberId = Cstr(dblMemberId)
end if
rsUsers.AddNew
rsUsers("MemberId") = strMemberId
I think it has something to do with the cast operators but cant figure it out, Please Help.
|