It appears a couple things are happening, the first is since you are writing a RandomAccess file the Records need to be of the same length, therefore your Structure needs to be setup something like this (Since you didn't post your structure/class I am guessing that this could be a problem, if not the second issue is probably what is causing your issue).
Public Structure User
Public UserId As Integer
<VBFixedString(50)> Public UserBarCode As String
<VBFixedString(20)> Public Forename As String
<VBFixedString(20)> Public Surname As String
<VBFixedString(20)> Public AccessRights As String
End Structure
The second is that your RecordNumber
is not valid you are just getting the length of an Integer(your UserFile Variable). By giving your structure a fixed size you can use the LOF
Method to get the length of your open file then divide that by your record size to determine the amount of records something like this.
RecordNumber = (LOF(UserFile) \ Len(UserToAdd)) + 1
As I said in my comment these functions are left over from VB6, but I can see why you would want to use them, there appears to be a lack of information on any other way.