How can I find out which rows have been selected in a datasheet view?

G

Guest

I have a form which is displaying my records in datasheet view. (MS Access
2003)

I have my record selectors option switched on and want to find a way by
which when a button is clicked I can determine which of the rows have beens
selected.

Can anyone tell me how I can do this? I would prefer not to have to resort
to a listbox if at all possible.

Many thanks


J Macleod
 
D

Dirk Goldgar

I have a form which is displaying my records in datasheet view. (MS
Access 2003)

I have my record selectors option switched on and want to find a way
by which when a button is clicked I can determine which of the rows
have beens selected.

Can anyone tell me how I can do this? I would prefer not to have to
resort to a listbox if at all possible.

The form's SelTop property will return the number of the first selected
row, and the SelHeight property will return the number of selected rows.
But where will this button be, if the form is displayed in datasheet
view?
 
G

Guest

I have the datasheet view appearing as a subform from my mainform where I
will place the buttons.
 
G

Guest

..SelTop works well returning the row number of the first row I have selected
however .SelHeight always returns zero.
 
D

Dirk Goldgar

.SelTop works well returning the row number of the first row I have
selected however .SelHeight always returns zero.

By the time your button on the main form receives the focus, the
selection has been cleared. What you have to do is use the subform
control's Exit event to capture the values and save them in module-level
variables. IFor example,

'----- start of example code for form module -----
Option Compare Database
Option Explicit

Dim mSelTop As Long
Dim mSelHeight As Long

Private Sub cmdShowSelection_Click()

MsgBox "SelTop=" & mSelTop & ", SelHeight=" & mSelHeight

End Sub

Private Sub sfMySubform_Exit(Cancel As Integer)

mSelTop = Me.sfMySubform.Form.SelTop
mSelHeight = Me.sfMySubform.Form.SelHeight

End Sub

'----- end of example code for form module -----
 

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