Solved open form with last record

kobiashi

Registered User.
Local time
Today, 05:13
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?
 
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:
Try:
DoCmd.GoToRecord , , acLast
will that work from the button click?
also what would that openm a specific form?
 
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:
"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.
 
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.
 
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
 
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:
thanks everyone for your replies, ive resolved this issue now by use of Docmd.GoToRecord ,, acLast. this did what i wanted
 
Last edited:
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

Back
Top Bottom