how to update field sequential number in subform

sparc

Registered User.
Local time
Today, 13:31
Joined
Jul 29, 2013
Messages
18
Hi,
1. Which event occurs when anything changes on subform (Delete row , add row , perform the sort, Especially when you add a row to be inserted in the current sorting between the rows)
2. I have column sequential number that need updating when occurs any event on subform
3. "On current" is event that occurs always when changing rows in subform, how to process rows sequential (row by row) thru subform and update field that represent sequential number.
Many pages are on google, but no solution.
 
I like to share my solution when I find that I can be useful to others in the community , and also would like to thank everyone who participated by giving me advice.
I'm always grateful amendments and suggestions for enhancements to the solution.
Note:
1. field RedBr is sequential number filed and it is not pk and not foreign key in another table
2. Process only rows filtered in subform

Private Sub Form_Current() ’for acept resort by any column
ReSort
End Sub

Private Sub Form_AfterUpdate() ’if exists resort by anu column this is accept
ReSort
End Sub

Private Sub Form_AfterDelConfirm(Status As Integer) ’ When delete more rows and when occurs
’error folowing procedure is ignore, but when
’occurs error for any row and accept delete
’ another rows this procesure is execute
If Status = 0 Then
Dim rst As DAO.Recordset
Dim i As Long
i = 0
Set rst = Me.Form.RecordsetClone
If rst.RecordCount > 0 Then rst.MoveFirst
While Not rst.EOF
rst.Edit
i = i + 1
rst!RedBr = i
rst.Update
rst.MoveNext
Wend
rst.Close
End If
End Sub

Public Sub ReSort()
Dim rst As DAO.Recordset
Dim i As Long
i = 0
Set rst = Me.Form.RecordsetClone
If Not rst.EOF Then rst.MoveFirst
While Not rst.EOF
rst.Edit
i = i + 1
rst!RedBr = i
rst.Update
rst.MoveNext
Wend
rst.Close
End Sub
 

Users who are viewing this thread

Back
Top Bottom