Mr_Adams
Active Member
- Joined
- Oct 7, 2002
- Messages
- 475
I use the attached code (when button is pushed) to input the next number onto a sheet.
Now, with many different user accessing the same text file, I worry they may do so at the same time creating errors.
Would it be possible to look and see if the file is in use before allowing the next user. So basically loop the until the file is avaible or timeout after a mintue.
Or am I just over thinking this and should I leave the code alone.
Now, with many different user accessing the same text file, I worry they may do so at the same time creating errors.
Would it be possible to look and see if the file is in use before allowing the next user. So basically loop the until the file is avaible or timeout after a mintue.
Or am I just over thinking this and should I leave the code alone.
Code:
Dim ThisInvoice As Long
Dim ReadText As String
Dim StoreFile As String
'read previous number:
If Dir(StoreFile) = "" Then 'not found
ThisInvoice = 1
Else
Open StoreFile For _
Input Access Read As #1
While Not EOF(1)
Line Input #1, ReadText
ThisInvoice = Val(ReadText)
Wend
Close #1
End If
ThisInvoice = ThisInvoice + 1
'Store this number:
Open StoreFile For _
Output Access Write As #1
Print #1, ThisInvoice
Close #1
With ActiveSheet.Range("C5") 'change to suit
.Value = ThisInvoice
End With