Sorry, this is my second post.
We have the same problem, I have had a peer to peer network, in which the
shared mdb resides in desktop pc, two laptops accessing the shared SharedData.
mdb, okay, we used the primary key whici is the autonumber, but...we have the
record number which is unique, my record number starts TSND00001, TSND00002...
AND SO ON, when the two users entering the product code, it happens that they
are on the same unique number......Please help me regarding this, is there
any chance to correct this scenario, we just starting only this year to
transfer our data form excel sheets, we are very new in vb code......thanks!
==================================================================
We are NGO (Non-Government Organization) and solicitation comes from variety
of good people / oraganization, we are non-profit organization dealing on
relief goods for less fortunate people, everyday, one company is being added
to our database NGGO and we want to create UNIQUE PRIMARY KEY BASED ON THE
FOLLOWING:
Fields1(Counter) Fields2(strNGGO) NGONumber
000001 NGGO NGGO000001
000001 NGGO NGGO000002
000001 NGGO NGGO000003
000001 NGGO NGGO000004
000001 NGGO NGGO000005
and so on, and so forth......
two desktop pc's accessing the database in shared/split format. everytime,
the two user creating making/creating new NGONumber they are making
duplicates and we are facing problems on this.
BY THE WAY, I'VE CREATED A COMMAND BUTTON FOR NEW NUMBER
Is there any chance you could help us regarding the above problem?
Ken said:
You can look up the last number (if any) for the document type for the
current year and add 1. This would be done in the AfterUpdate event
procedure of a control bound to a column in which the document type is
recorded, so if this is called DocumentType and the column for the number is
called ControlNumber then the code would go like this:
Dim ctrl as Control
Dim strYear as String
Dim strCriteria As String
Set ctrl = Me.ActiveControl
strYear = Format(VBA.Date,"yy")
strCriteria = "DocumentType = """ & ctrl & """ " & _
"And Left(ControlNumber,2) = """ & strYear & """"
If Not IsNull(ctrl) Then
Me.ControlNumber = strYear & "-" _
Format(Nz(DMax("Right(ControlNumber,4)", _
"YourTable",strCriteria),0)+1,"0000")
Else
Me.ControlNumber = Null
End If
This should work fine in a single-user environment, but a conflict could
arise in a multi-user environment if two or more users are adding a record
for the same document type simultaneously as they'd all get the same number.
Provided you have a unique index on the DocumentType and ControlNumber
columns (in combination, not individually) the first user saving the record
would be successful, but subsequent users would experience an error, so there
would be no possibility of duplicate numbers for the same document type.
There are ways of preventing two users getting the same number and you'll
find one described in my reply in the following thread, which deals with a
similar scenario:
http://www.microsoft.com/office/com...rted&mid=da6995be-f180-4b1d-ac56-8693f4db7008
Ken Sheridan
Stafford, England
I posted the following question to the wrong Access group. My apologies!
[quoted text clipped - 11 lines]
Thanks, in advance, for your advice, and sorry again for posting this twice.