code to send scroll bar to bottom of subform

ellenr

Registered User.
Local time
Today, 12:59
Joined
Apr 15, 2011
Messages
400
Is there a way to move/keep the subform's scroll bar to the bottom so the most recent records are visible?
 
The easiest wat is just to sort the subform in reverse order with latest record at the top
 
I have already tried that--just didn't like the way it looked. I guess I will have to settle for that. Thanks for answering.
 
I said it was the easiest way - not the only way.

You could use the expression:
DoCmd.GoToRecord(ObjectType, ObjectName, Record, Offset)

Something like:
Code:
DoCmd.GoToRecord, , acLast
 
And if you want to be sure to see, say, the last ten Records, you can use something like this:

Code:
Private Sub Form_Load()

Dim i as Integer

DoCmd.GoToRecord , , acLast

 For i = 1 To 9
   DoCmd.GoToRecord , , acPrevious
 Next
 
End Sub
replacing the 9, in the above code, with the number of Records you want minus 1.

Linq ;0)>
 
So simple! Why didn't I think of that? Thanks so much.
 
Well, I thought it was simple! The following code throws a compile error. I have deleted it, reentered it, done compact and repair, etc., and finally imported the whole thing into a new db. What am I doing wrong?


Code:
        Me.[piecework subform].SetFocus
        DoCmd.GoToRecord , , acLast
        i = DCount("n", "pieceworkq")
        If i > 25 Then
            [COLOR="Red"]For k = 1 to 25       'compile error: syntax error[/COLOR]
            DoCmd.GoToRecord, , acPrevious
            Next
        End If
 
Yes, both i and k are defined as integers.
 
I just commented out the if-end if lines and retyped them below and all works! Thanks for looking at it. 'Tis a mystery.
 
looks ok to me

try this as an alternative

docmd.gotorecord,,,acgoto,i-25

I'M WRITING THIS ON MY PHONE AND CAPS LOCK IS STUCK. SORRY
THERE MAY BE TYPOS DO CHECK
 
Oh dear! hope your phone gets well soon! Thanks for the suggestion--now that my code is working I think I won't touch it again for fear of breaking it. Have a good day!
 
Just rebooted and ok now!

I suggested the alternative as it should be quicker than looping 25 times
 
If your object is to make sure that you have at least 25 Records, before doing this (which is a good idea) this will do that, and if the number of Records is less than 25 will show all the records:

Code:
Private Sub Form_Load()
  
  DoCmd.GoToRecord , , acLast
  
  DoCmd.GoToRecord , , acFirst
  
  If RecordsetClone.RecordCount > 25 Then
    For k = 1 To 25
      DoCmd.GoToRecord , , acPrevious
    Next
  Else
    For k = 1 To RecordsetClone.RecordCount - 1
      DoCmd.GoToRecord , , acPrevious
    Next
  End If
  
End Sub
Linq ;0)>
 

Users who are viewing this thread

Back
Top Bottom