|
-
October 8th, 2004, 08:14 AM
#3
Re: Unique invoice number multi user
The important thing is to LOCK the record before reading it
If someone else is currently using that record, then you will get an error, which simply tries to get the record again - hopefully now it has been freed
On Error goto LockErr
Lock InvoiceNumberRecord
InvoiceNumberTable.Read(next)
InvoiceNumberTable.Edit
InvoiceNumber = InvoiceNumber + 1
MyNewNumber = Invoice Number
InvoiceNumberTable.Update
UnLock InvoiceNumberRecord
Exit Sub
LockErr:
Resume Next
not quite sure what type of file you are storing the invoice number in -
hope this helps
THIS IS FROM VB HELP ON "LOCK"
Lock, Unlock Statements Example
This example illustrates the use of the Lock and Unlock statements. While a record is being modified, access by other processes to the record is denied. This example assumes that TESTFILE is a file containing five records of the user-defined type Record.
Type Record ' Define user-defined type.
ID As Integer
Name As String * 20
End Type
Dim MyRecord As Record, RecordNumber ' Declare variables.
' Open sample file for random access.
Open "TESTFILE" For Random Shared As #1 Len = Len(MyRecord)
RecordNumber = 4 ' Define record number.
Lock #1, RecordNumber ' Lock record.
Get #1, RecordNumber, MyRecord ' Read record.
MyRecord.ID = 234 ' Modify record.
MyRecord.Name = "John Smith"
Put #1, RecordNumber, MyRecord ' Write modified record.
Unlock #1, RecordNumber ' Unlock current record.
Close #1 ' Close file.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|