Records selected in subform

Pat
5StarLounger
Posts: 1148
Joined: 08 Feb 2010, 21:27

Records selected in subform

Post by Pat »

Is there a way to determine which rows of a subform have been selected?

If not i will have to introduce a check box to indicate which records have been selected.

User avatar
HansV
Administrator
Posts: 78493
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Records selected in subform

Post by HansV »

The SelTop property of a datasheet or continuous form is the record number (starting from 1) of the first selected record, and the SelHeight property is the number of selected records.
Best wishes,
Hans

Pat
5StarLounger
Posts: 1148
Joined: 08 Feb 2010, 21:27

Re: Records selected in subform

Post by Pat »

Thank you, where is that described in the documentation?

User avatar
HansV
Administrator
Posts: 78493
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Records selected in subform

Post by HansV »

In the properties of the Form object.
Also see SelTop Property and SelHeight Property.
Best wishes,
Hans

Pat
5StarLounger
Posts: 1148
Joined: 08 Feb 2010, 21:27

Re: Records selected in subform

Post by Pat »

How would you then reference these records in a continuous form. I have found something that will do it, however i am having trouble adressing the subform called deplist. The Set F code below results in a 13 Type Mismatch error:

Code: Select all

   Dim F As Form
   Set F = Me.deplist
I have overcome this by
Set F = Me.deplist.form

This is the code to address selected records in a subform, but the SelHeight returns a zero.

Code: Select all

   Dim i As Long
   Dim F As Form
   Dim RSf As dao.Recordset

   ' Get the form and its recordset.
   Set F = Me![deplist].Form
'   Set F = Forms![Department Availability]!deplist.Form
   Set RSf = F.RecordsetClone

   ' Move to the first record in the recordset.
   RSf.MoveFirst

   ' Move to the first selected record.
   RSf.Move F.SelTop - 1

   ' Enumerate the list of selected records presenting
   ' the CompanyName field in a message box.
   For i = 1 To F.SelHeight
     MsgBox RSf![DepartmentID] & " " & RSf!DefaultTech
     RSf.MoveNext
   Next i
   RSf.close
   Set RSf = Nothing
Can you help me?

Pat
5StarLounger
Posts: 1148
Joined: 08 Feb 2010, 21:27

Re: Records selected in subform

Post by Pat »

I saw a google by Stephan Lebans describing it.

Introduce a couple of controls on the Main form, then in the Form_Click of the subform deplist I saved both the SelTop and SelHeight in the main controls of the main form.