Scrolling a subform to the last record on open

Mike-palmer

Registered User.
Local time
Today, 08:33
Joined
Mar 27, 2003
Messages
37
Is there a way to automatically scroll a subform on opening so the subform is filled with the last few records along with the new record data entry line?

Thanks for any help,
Mike
 
I would try something like this in the OnLoad event of the form:
Code:
Me.SubFormControl.SetFocus                      '-- Set Focus to the SubFormControl 1st
Me.SubFormControl.Form!txtControl.SetFocus '-- Now set Focus to a control on SubForm
DoCmd.RunCommand acCmdRecordsGoToLast           '-- And move to the last record
Using your control names of course.
 
Thanks Ruralguy ...

I tried it but I'm a little confused ... is it theon-open property of the subform or the main form?

Mike
 
It is the OnLoad event of the MainForm. The Open event is too early in the sequence. If you always want this SubForm to go to the last record then you could put different code in the SubForm itself.
 
It's the sub-form that I need to scroll to the last record. I tried the following code in the "on-load" for the sub-form, but it doesn't scroll down ...

Me.Comment.SetFocus
DoCmd.RunCommand acCmdRecordsGoToLast


I thought I was getting better at Access, but then it throws something like this at me and what should be simple seems overly complex! Thanks for your help.

Mike
 
Put this in the OnLoad event of the Main Form. (as RG Suggested)


Code:
Me.[COLOR="Blue"]sfrmMySubForm[/COLOR].SetFocus
DoCmd.GoToRecord , , acNewRec
DoCmd.GoToControl [COLOR="Blue"]"txtComment"[/COLOR]

This is what I have used and it works fine. Change the "Blue" text to suit.

The last line in the code will take the curzor to the control that you want to start your data entry at.

I see no reason to put this code in the subform, if your subform form is part of a 1-many relationship then you can't enter data into the subform without a corresponding entry in the main form.
 
Thanks Ansentry, that worked great when the form loads the first time ... but when I change the customer on the main form and the subform updates to show the comments relevant to that customer, it doesn't go to the last record on the subform. I tried adding the same code in the "after-update" event, but it didn't help. Any idea where to put the code so that when the mani form's record changes the sub form scrolls to the end ....

Mike
 
Many thanks to all That solved the scroll problem completely for me ... and finding out what "current" is for solved a couple of other work-arounds that I've been using.

I loveAccess when it's working ... but gee it's sometimes very frustrating getting it there!
 

Users who are viewing this thread

Back
Top Bottom