Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enumerate selection within subform MS modification

Status
Not open for further replies.

englundn

Programmer
Jun 1, 2007
23
FI
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
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top