Creating a Default OrderBy

BrynJ

New member
Local time
Today, 16:00
Joined
Feb 10, 2004
Messages
8
I've several forms that are based on queries. These are all displayed in a Datasheet view. I want these forms sorted in a certain order by default. I realise I can add these sort orders either in the query or in the OrderBy property in the form.

I have tried both and I'm not sure which is preferable. However, I seem to have a problem with both methods in that if I change the sort order in my application and close the form it retains this sort order when the form is next reopened (and indeed until I manually change the order back to my required default sort).

Is there any way to get these default orders to 'stick' as it seems strange that Access is so keen to overwrite my defined sorts?

Thanks,

Bryn.
 
Access is remembering your latest sort options when you close the form. Use the forms OnOpen event to reset your "default" sort order with VBA.

HTH
 
Thanks for the reply ghudson. What would the VBA look like for the OnOpen event? I'd be greatful if you could give an example :)

Bryn.
 
Check the Access help files for the OrderByOn & OrderBy properties
if you are not clear on how to use them.
Code:
Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Form_Open
    
    Me.OrderByOn = True
    Me.OrderBy = "Field1,Field2,Field3"
    
Exit_Form_Open:
    Exit Sub
        
Err_Form_Open:
    MsgBox "Run-time error # " & Err.Number & "." & vbCrLf & vbLf & Err.Description
    Resume Exit_Form_Open
    
End Sub
 
Sorry I'm late replying, cheers for the help - I will try it out later :)

Bryn.
 

Users who are viewing this thread

Back
Top Bottom