Help with SelTop

G

Guest

I'm trying to identify which records are selected in a subform (datasheet
view). I've got my code working fine, but I can't find which even to put it
behind that it will work 100% of the time.

Some examples of what I've found:
- Putting it behind the "On Click" command will work, as long as you release
the mouse button while your cursor is over the record selector column. If
you move it over the data when you release, the code won't run
- Putting it behind the timer causes all sorts of problems, and never seemed
to kick off when I needed it to
- Putting it behind the On Mouse Up did the same problem as the "On Click
command"

You get the idea on the rest. Just in case, the code I used is below.
Obviously this code just displays the record numbers in a MsgBox, but that is
just to keep this short.

Thanks in advance!
Kevin

*------Code start------*
Dim rs As DAO.Recordset
Dim lng As Long
Dim curTotal As Currency
Dim varPN
Dim varSQL As String

Set rs = Me.RecordsetClone

If rs.RecordCount > 0 Then
rs.MoveFirst
rs.Move Me.SelTop - 1
Do While lng < Me.SelHeight And Not rs.EOF
'here
varPN = rs![PN]
MsgBox varPN

rs.MoveNext
lng = lng + 1
Loop
End If

SumSelectedRows = curTotal
Set rs = Nothing
 
S

Stephen Lebans

Create two module level variables. Place them in the General
Declarations area at the top of your form.:

Dim lSelTop as long
DIm lSelHeight as long


Now in the Datasheet Form's Click event and the Current event do
something like:

lSelTop = Me.SelTop
lSelHeight = Me.SelHeight

If I remember correctly, Access changed the SelTop property to be zero
based intead of ones based as it was prior to A2K(or vice versa).



--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
G

Guest

Thanks a lot Stephan- I appreciate your help. Thank you too for posting the
code on your website- that's how I first learned about SelTop.

Stephen Lebans said:
Create two module level variables. Place them in the General
Declarations area at the top of your form.:

Dim lSelTop as long
DIm lSelHeight as long


Now in the Datasheet Form's Click event and the Current event do
something like:

lSelTop = Me.SelTop
lSelHeight = Me.SelHeight

If I remember correctly, Access changed the SelTop property to be zero
based intead of ones based as it was prior to A2K(or vice versa).



--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.


Kevin said:
I'm trying to identify which records are selected in a subform (datasheet
view). I've got my code working fine, but I can't find which even to put it
behind that it will work 100% of the time.

Some examples of what I've found:
- Putting it behind the "On Click" command will work, as long as you release
the mouse button while your cursor is over the record selector column. If
you move it over the data when you release, the code won't run
- Putting it behind the timer causes all sorts of problems, and never seemed
to kick off when I needed it to
- Putting it behind the On Mouse Up did the same problem as the "On Click
command"

You get the idea on the rest. Just in case, the code I used is below.
Obviously this code just displays the record numbers in a MsgBox, but that is
just to keep this short.

Thanks in advance!
Kevin

*------Code start------*
Dim rs As DAO.Recordset
Dim lng As Long
Dim curTotal As Currency
Dim varPN
Dim varSQL As String

Set rs = Me.RecordsetClone

If rs.RecordCount > 0 Then
rs.MoveFirst
rs.Move Me.SelTop - 1
Do While lng < Me.SelHeight And Not rs.EOF
'here
varPN = rs![PN]
MsgBox varPN

rs.MoveNext
lng = lng + 1
Loop
End If

SumSelectedRows = curTotal
Set rs = Nothing
 

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