Solved Have subforms last record focused (1 Viewer)

oxicottin

Learning by pecking away....
Local time
Today, 16:02
Joined
Jun 26, 2007
Messages
851
Hello, I have a form with a subform and on the subform I usually enter 15 records or so. How can I always have the last and new if there is no records scrolled to so they are always visible when I go to each record from my main form and if im entering a record or working on a record.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 13:02
Joined
Oct 29, 2018
Messages
21,358
Hi. Look into DoCmd.GoToRecord. Hope that helps...
 

oxicottin

Learning by pecking away....
Local time
Today, 16:02
Joined
Jun 26, 2007
Messages
851
I tried the below and the subform kinda flickers but the first record is visable and I have to school to next to last
Code:
DoCmd.GoToRecord , , acGoTo, Form.Recordset.RecordCount - 2
'set focus on the last record
DoCmd.GoToRecord , , acLast
 

theDBguy

I’m here to help
Staff member
Local time
Today, 13:02
Joined
Oct 29, 2018
Messages
21,358
I tried the below and the subform kinda flickers but the first record is visable and I have to school to next to last
Code:
DoCmd.GoToRecord , , acGoTo, Form.Recordset.RecordCount - 2
'set focus on the last record
DoCmd.GoToRecord , , acLast
Can you post a sample copy of your db with some test data?
 

neuroman9999

Member
Local time
Today, 15:02
Joined
Aug 17, 2020
Messages
827
How can I always have the last and new if there is no records scrolled to so they are always visible when I go to each record from my main form and if im entering a record or working on a record.
agree with dbGuy. post a sample. however, are you asking if you can always SEE records on your sub, regardless of what you are tinkering with inside your main form? that's what it sounds like.
 

oxicottin

Learning by pecking away....
Local time
Today, 16:02
Joined
Jun 26, 2007
Messages
851
To much to personal info to get rid of ect. This isn't a needed to do its just a want to do.... Thanks anyway!
 

theDBguy

I’m here to help
Staff member
Local time
Today, 13:02
Joined
Oct 29, 2018
Messages
21,358
To much to personal info to get rid of ect. This isn't a needed to do its just a want to do.... Thanks anyway!
How about creating a demo db with a similar structure as the forms you're having issues with? Just a thought...
 

missinglinq

AWF VIP
Local time
Today, 16:02
Joined
Jun 20, 2003
Messages
6,423
This has worked for me for a number of years:
Code:
Private Sub Form_Current()
  Me.SubformName.SetFocus
  DoCmd.GoToRecord , , acNewRec
  Me.SubformName.Form!FirstControlName.SetFocus
End Sub
Linq ;0)>
 

Gasman

Enthusiastic Amateur
Local time
Today, 20:02
Joined
Sep 21, 2011
Messages
14,047
This is what I do
Code:
Private Sub Form_Open(Cancel As Integer)
    Me.RecordSource = "qryEmails"
    Me.sfrmEmails.SourceObject = "cfrmEmails"
    Set Me.sfrmEmails.Form.Recordset = Me.Recordset
    DoCmd.RunCommand acCmdRecordsGoToLast
    DoCmd.GoToRecord acDataForm, Me.Name, acPrevious, 5 ' Needed for a continuous form as only last record shows.
    DoCmd.RunCommand acCmdRecordsGoToLast
    DoCmd.Maximize
End Sub
 

oxicottin

Learning by pecking away....
Local time
Today, 16:02
Joined
Jun 26, 2007
Messages
851
It works sorta if I use the code below to bring it to the last record and not the previous 2 but im ok with it....

Code:
Private Sub Form_Current()
    
    Dim sfrm1 As Control, sfrm2 As Control
    
    If Me.NewRecord Then
'Do nothing if new record
    Else
        Set sfrm1 = Forms!frm_ShiftDay!frm_ShiftMachinesRanSubform
        Set sfrm2 = sfrm1.Form!frm_MachineOutputSubForm
        
        sfrm1.SetFocus
        sfrm2.SetFocus

        Set sfrm2 = Nothing
        Set sfrm1 = Nothing
'set focus on the last record
        DoCmd.GoToRecord , , acLast
    End If
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 16:02
Joined
Feb 19, 2002
Messages
42,973
You could change the subform's RecordSource query to sort descending on a date field or on the autonumber. That will show the newest record on top.
 

Users who are viewing this thread

Top Bottom