I'm using Visual Basic 6.0 to build a front end for a database for storing cars. The vehicles are stored with a log number that I want to auto populate each time a new record is added. The problem I'm having is two fold, sometimes the number that is given using the movelast command is not accurate (curious how it decides which record is the last one?). Also what what be the easiest way to allow two computers access to this feature and have them both be able to add records at the same time with unique log numbers? I was thinking of having the record added with the new log number and then using update instead of add that way when the next machine attempts to pull the new log number it will see the record currently being added? The only problem I see with this logic is that if you decided to cancel the addition of the record in that maner and it was deleted it would then skip a log number next time.
Anyway I know thats a lot of information below is the code currently being used to pull the last log number from the database and add 1 to it. If you guys have any questions about the issue please ask away.
Private Sub Form_Activate()
Dim templognum As Integer
frmMain.Hide
datPrimaryRS.Recordset.Mov
eLast 'This should be moving to the last record but does not appear to reliably do so
templognum = txtfields(0).Text + 1 'This pulls the current log number from the last record and adds 1
datPrimaryRS.Recordset.Add
New
txtfields(1).Text = Format(Now(), ("mm/dd/yy")) 'This line is adding today's date to a text field
txtfields(0).Text = templognum 'This assigns the new log number to a text field
txtfields(2).SetFocus
End Sub
Start Free Trial