I struggled with the problem to update records in a subform, i got some good advice from people here, thanks Remou. I just want to make a simplified version of Microsoft's solution that can be used in a subform. My version isn't completely used as a function, but as a sub. There is nothing that prevents to make it totally as a function.
MS article
I just found it easier to make the "beta" version in the form like this:
Declare variables in a module
Within a form used as Datasheet put a mouse up event, which will write the selection to the public variables.
After that have a button (instead of the macro that was used in the article), which calls the following function.
I hope this will help people that are working with the same kind of problem. The main problem that i got with the original MS functions were related to the mouse move and mouse down, which i think are unnecessary.
MS article
I just found it easier to make the "beta" version in the form like this:
Declare variables in a module
Code:
'Declaration of variables used in multiupdating function
Public MySelTop As Long
Public MySelHeight As Long
Within a form used as Datasheet put a mouse up event, which will write the selection to the public variables.
Code:
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
MySelTop = Me.SelTop
MySelHeight = Me.SelHeight
End Sub
After that have a button (instead of the macro that was used in the article), which calls the following function.
Code:
Function updateRecord()
Dim i As Long
Dim F As Form
Dim RS As Recordset
' Get the form and its recordset.
Set F = Forms!xTestUpdating.Child0.Form
Set RS = F.RecordsetClone
' Move to the first record in the recordset.
RS.MoveFirst
' Move to the first selected record.
'RS.Move F.SelTop - 1 Original
RS.Move MySelTop - 1
' Enumerate the list of selected records presenting
' the CompanyName field in a message box.
'For i = 1 To F.SelHeight Original
For i = 1 To MySelHeight
RS.Edit
RS!ok = True
RS.Update
RS.MoveNext
Next i
End Function
I hope this will help people that are working with the same kind of problem. The main problem that i got with the original MS functions were related to the mouse move and mouse down, which i think are unnecessary.