setting the vertical position of a tabular subform when the main form opens

P

Paul Ponzelli

Is there a way to automatically set the vertical position of a tabular
(continuous) subform when the main form opens?

I have a subform with more records than are visible at one time without
scrolling vertically. So whenever I want to enter a new record in the
subform (or view the most recently-entered records) I need to drag the
vertical scroll bar down to make those recent records and the new record row
visible.

It would be nice if, when the form opens, the subform is vertically
positioned so that the new record row (and the most recent records) are
visible at the bottom of the subform, so the user doesn't have to manually
scroll down to the bottom of the recordset every time a new entry is made.

Is there a way to accomplish this?

Thanks in advance,

Paul
 
P

Paul Ponzelli

Thanks for telling me how to solve this problem, Klatuu.

When you suggested using the MoveLast method of the Recordset object, it
occurred to me that I could also write a loop to go through a number of
MovePrevious steps so that the last record wouldn't be the only record
displayed in the subform. Now whenever I move to a new record in the main
form, the most recent records fill the subform display without requiring any
vertical scrolling. For anyone that's interested, here's what I used to do
that:

Dim k As Integer
Dim numRecords As Integer
numRecords = Me!frmActivitySub.Form.Recordset.RecordCount
If numRecords > 16 Then
Me!frmActivitySub.Form.Recordset.MoveLast
k = 0
For k = 1 To (numRecords - 1)
Me!frmActivitySub.Form.Recordset.MovePrevious
If k = 15 Then Exit For
Next k
End If

Thanks (again) for showing me the way.
 
M

Marshall Barton

That's the long way around to display the last 16 records.

Me!frmActivitySub.Form.Recordset.MoveLast
If numRecords > 16 Then
Me!frmActivitySub.Form.Recordset.Move -15
End If
 
P

Paul Ponzelli

That's even better.

An additional problem with my less efficient method was that every time I
moved back a record, it triggered the form's Current event, which has
several things going on. So your solution has eliminated that problem as
well.
Testing to see if there are more than 16 records is also a good idea because
not all of the recordsets have that many records.

Thank you, gentlemen.

Paul
 

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