This part of my program is designed to add user details to a random access file. The sub routine below is designed to do this:
'This allows a user to be added to the User File
Dim UserToAdd As User
Dim UserFile As Integer
Dim RecordNumber As Long
'Read the data off the form and populate corresponding
'UserToAdd values
With UserToAdd
.UserID = Val(txt_UserID.Text)
.UserBarcode = txt_UserBarcode.Text
.Forename = txt_Forename.Text
.Surname = txt_Surname.Text
.AccessRights = cmb_AccessRights.Text
End With
'Find the next open space in the User File
UserFile = FreeFile()
'Now open the file used to store User records
FileOpen(UserFile, UserFileName, OpenMode.Random, OpenAccess.Write, OpenShare.Shared, Len(UserToAdd))
RecordNumber = Len(UserFile) + 1
'Add the new user to the file
FilePut(UserFile, UserToAdd, RecordNumber)
FileClose(UserFile)
There are no problems in actually saving the details, however, the file is overwritten every time another record is added. How could I stop this and what have I done wrong above?