我的程序的这一部分旨在将用户详细信息添加到随机访问文件中。下面的子例程旨在执行此操作:
'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)
实际保存详细信息没有问题,但是,每次添加另一条记录时,文件都会被覆盖。我怎么能阻止这个,我在上面做错了什么?