Solved open form with last record (1 Viewer)

kobiashi

Registered User.
Local time
Today, 00:01
Joined
May 11, 2018
Messages
258
Hi all,

Im trying to open a form to the last record via a button but cant seem to find the correct command so i currently have

Code:
sub CmdOpenForm_Click()
       DoCmd.OpenForm FormName:="FrmEventNewTrackPart", DataMode:= acLastRecord
End Sub


But that doesnt work

can i run a DoCmd.OpenForm followed by DoCmd.GoToRecord from the button?
 

vhung

Member
Local time
Yesterday, 16:01
Joined
Jul 8, 2020
Messages
235
Hi all,

Im trying to open a form to the last record via a button but cant seem to find the correct command so i currently have

Code:
sub CmdOpenForm_Click()
       DoCmd.OpenForm FormName:="FrmEventNewTrackPart", DataMode:= acLastRecord
End Sub


But that doesnt work

can i run a DoCmd.OpenForm followed by DoCmd.GoToRecord from the button?
Try:
DoCmd.GoToRecord , , acLast
 
Last edited:

kobiashi

Registered User.
Local time
Today, 00:01
Joined
May 11, 2018
Messages
258
Try:
DoCmd.GoToRecord , , acLast
will that work from the button click?
also what would that openm a specific form?
 

vhung

Member
Local time
Yesterday, 16:01
Joined
Jul 8, 2020
Messages
235
will that work from the button click?
also what would that openm a specific form?
Could be applied using "Button" after open a form
DoCmd.OpenForm "FrmEventNewTrackPart"

then set on "Event Procedure" during "Form Load" that if last record is required always to viewed.
DoCmd.GoToRecord , , acLast
 
Last edited:

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 19:01
Joined
Feb 19, 2002
Messages
43,302
"last" has no fixed meaning in a relational database because queries and tables are by definition unordered sets. If by "last" you mean last entered, you can find the PK for that by using a DMax("MyPK", "SomeTable") and then using that in a queyr. This presumes that your PK is an autonumber or other sequentially generated ID. If by "last" you mean the record with the highest date, you would have to include time in your date if there could be more than a single entry per day AND your application would have to be not so busy that there could be duplicate timestamps generated.

Anytime you use Last in any way including the suggestion above, you will be getting the last item physically retrieved which will not always be what you anticipated. For example, you have 1000 records in your table and 1000 is the "last" one entered. However you also updated record 322 and as a result increased the record size. That means that Access couldn't put it back where it got it from because it won't fit so it puts it at the end. So now the table is 1-321,323-1000, 322 and 322 is now the last record. Any newly updated record can end up as "last" if the edit increased its size.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 18:01
Joined
Feb 28, 2001
Messages
27,193
As you have been advised by others, "Last" is a questionable term in a relational database. If "Last Record" means the record changed most recently then then you must have a way to remember either WHEN something was changed (like a date/time field for "last updated on") or IN WHAT ORDER something was changed (like some sort of autonumbering scheme that updates record numbers of updated records.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 07:01
Joined
May 7, 2009
Messages
19,245
Code:
Sub CmdOpenForm_Click()
       DoCmd.OpenForm FormName:="FrmEventNewTrackPart"
      
       'arnelgp
       With Forms!FrmEventNewTrackPart.Recordset
            If Not (.BOF And .EOF) Then
                .MoveLast
            End If
        End With

End Sub
 

vhung

Member
Local time
Yesterday, 16:01
Joined
Jul 8, 2020
Messages
235
Or by using cmdOpenForm button then insert;

DoCmd.OpenForm "FrmEventNewTrackPart": DoCmd.GoToRecord , , acLast

MsgBox "FormLoaded goto LastRecord... " _
& vbCrLf & "ID: " & Forms![FrmEventNewTrackPart]![ID] & "= " _
& Forms![FrmEventNewTrackPart]![ranyfield], vbInformation
 
Last edited:

kobiashi

Registered User.
Local time
Today, 00:01
Joined
May 11, 2018
Messages
258
thanks everyone for your replies, ive resolved this issue now by use of Docmd.GoToRecord ,, acLast. this did what i wanted
 
Last edited:

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 19:01
Joined
Feb 19, 2002
Messages
43,302
Trust me. It isn't working. It just looks like it is working because nothing got moved. This method will fail as soon as you have a second concurrent user or enough rows to require a second block (physical record).
 

Users who are viewing this thread

Top Bottom