fix sort code problem (1 Viewer)

qupe

Registered User.
Local time
Yesterday, 20:48
Joined
Feb 15, 2016
Messages
51
hi
i am using this code on click with button and it work well

Code:
DoCmd.ApplyFilter , "status='seen'"
DoCmd.SetOrderBy "ldate ASC"
DoCmd.GoToRecord acDataForm, Me.Name, acLast


but when i use it with form on load the filter and go to the last row does not work but the sort work so why ??


I appreciate any help
 

sneuberg

AWF VIP
Local time
Yesterday, 20:48
Joined
Oct 17, 2014
Messages
3,506
I tried to replicate you problem in the attached database and in this case it seems to work in the form load event. Could you upload your database. Maybe we can see what's different.
 

Attachments

  • FilterOnLoad.accdb
    400 KB · Views: 57

missinglinq

AWF VIP
Local time
Yesterday, 23:48
Joined
Jun 20, 2003
Messages
6,423
I can't get it to work at all! It bombs on

DoCmd.SetOrderBy "ldate ASC"

and, in point of fact, Access can't find any reference to SetOrderBy!

This does what you want, though, if I understand your need correctly:

Code:
Private Sub Form_Load()
  DoCmd.ApplyFilter , "status='seen'"
  Me.Form.FilterOn = True
  Me.Form.OrderBy = "[ldate] ASC"
  Me.Form.OrderByOn = True
  DoCmd.GoToRecord acDataForm, Me.Name, acLast
End Sub
Linq ;0)>
 

sneuberg

AWF VIP
Local time
Yesterday, 20:48
Joined
Oct 17, 2014
Messages
3,506
@missingling Interesting. It appears DoCmd.SetOrderBy is only good in Access 2010 and later

Your code does exactly what the OPs code does on my Access 2013 system.
 

missinglinq

AWF VIP
Local time
Yesterday, 23:48
Joined
Jun 20, 2003
Messages
6,423
Curiouser and curiouser! I hadn't heard of any Methods like this being added.

Wonder what version the OP is using, and if he/she used one version where it worked and another where it didn't?

Linq ;0)>
 

Users who are viewing this thread

Top Bottom