Go to last record on a subform

  • Thread starter Thread starter Edward G
  • Start date Start date
E

Edward G

Hi! I know this can't be difficult but I am going around in circles on this
one.
My main form is frmCustomers.
My subform is a datasheet called frmServiceRecordsSub.

What I want:
When frmCustomers opens, frmServiceRecordsSub should be showing the last
record.

Thanks.

Ed G
 
Hmmmm.
Said it wrong.
What I want:
frmServiceRecordsSub to show last record by default.

Thanks again.

Ed G
 
Edward,

Try putting code like this on the Current event of your frmCustomers form...
DoCmd.GoToControl Me.frmServiceRecordsSub
DoCmd.GoToRecord , , acLast
 
I tried cutting and pasting the code into the Current event and got:
"Compile error
Method or data member not found."

I figure if I live to be 100, the amount of time I save by not clicking the
last record button
at the bottom of the subform probably won't come anywhere close to the
amount of time
I have spent trying to figure out how to do this.

We need another newsgroup: microsoft.public.access.gettingfrustrated

Ed
 
Got it to work with:
DoCmd.GoToControl "frmServiceRecordsSub"
DoCmd.GoToRecord , , acLast

Probably tried this exact same code a dozen times before it finally worked.

Now, I have a new problem. I guess I should have mentioned that the subform
was
located on a tab. What is happening now is that when I make a selection of a
customer
name from the list box on the first tab I'm taken immediately to the service
history tab (the 4th tab) where
the last record is selected.
While I do want the last record of the subform to be selected (and it is
now, thanks), I don't necessarily want to jump to that tab immediately.
Is it doable?

Thanks,
Ed
 
Ed,

Apologies for the error in the code I gave you, and pleased to see
you've sorted it out.

There are two ways to proceed, now that we have the Tab Control coming
into the picture. One would be to put another DoCmd.GoToControl line at
the end of the code to shift the focus back to a main form control or to
a control on the first page of the tab control. I have not tried this,
but I imagine that this might result in an unsightly "flash" of the
screen as the focus moves back and forth rapidly. If so, an Echo False
at the beginning of the code block and Echo True at the end may help.
Give it a try.

Otherwise, another tack completely (caution: air code!)...
Dim rst As DAO.Recordset
Set rst = Me.frmServiceRecordsSub.Form.RecordsetClone
rst.MoveLast
Me.frmServiceRecordsSub.Form.Bookmark = rst.Bookmark
Set rst = Nothing
 
Back
Top