Determining selected records on subform in Datasheet view

D

Dan Nottheman

I have a main form with several command buttons that act on the
currently selected records on a subform.

Here's the subform code to store comma-delimited ids in a text box on
the parent form:

------------------------------------------------------------------

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As
Single, Y As Single)

Dim i As Integer
Dim strComma As String

If Me.SelHeight < 1 Then
Exit Sub
End If

Parent.txtIDs = ""

With Me.Recordset.Clone

..MoveFirst
..Move (Me.SelTop - 1)

For i = 1 To Me.SelHeight
Parent.txtIDs = Parent.txtIDs & strComma & Fields("id")
.MoveNext
strComma = ","
Next i

End With

Call MsgBox("MouseUp " & Me.SelHeight & " " & Parent.txtIDs)

End Sub parent form:

------------------------------------------------------------------

This works fine _unless the user has sorted the datasheet_. When that
happens, the recordsetclone order does not match the form's recordset
order and I get the wrong IDs returned. In other words, if rows 1, 2 and
3 are selected, I always return the same first 3 IDs in the recordset,
regardless of sort order.

Is there some way to make the clone order match the current order of the
form's recordset?

Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top