OrderBy property in Form_Open event

G

Guest

I have tried to place "Me.OrderBy = [Fieldname]" in a Form_Open event, but it
seems to be ignored. Is it not possible to establish the order of records in
the recordsource behind a form in code this way?

I know you can set the Order By form property in the form itself, but I want
to order the records conditionally in code, one order if opened for one
reason and another order if opened for another reason.

ctdak
 
R

Rick Brandt

ctdak said:
I have tried to place "Me.OrderBy = [Fieldname]" in a Form_Open
event, but it seems to be ignored. Is it not possible to establish
the order of records in the recordsource behind a form in code this
way?

I know you can set the Order By form property in the form itself, but
I want to order the records conditionally in code, one order if
opened for one reason and another order if opened for another reason.

ctdak

You are loading the gun but not pulling the trigger :)

You also need...

Me.OrderByOn = True
 
G

Guest

OK, thanks. The gun is now fired!

It seems a little odd to me though. OrderBy has a default of False, but if
you set it to True in code, then I notice that the form's Order By property
gets loaded with the field name(s). This means that if you remove the = True
code instead of changing it to = False, the ordering will continue unless you
also remove it from the form property. This could be a real gotcha.

It seems that it would be better if the form property were NOT loaded like
this at all. Then you could just put the OrderBy code line in with field
listed, or not, with no need to turn it on or off.

ctdak


Rick Brandt said:
ctdak said:
I have tried to place "Me.OrderBy = [Fieldname]" in a Form_Open
event, but it seems to be ignored. Is it not possible to establish
the order of records in the recordsource behind a form in code this
way?

I know you can set the Order By form property in the form itself, but
I want to order the records conditionally in code, one order if
opened for one reason and another order if opened for another reason.

ctdak

You are loading the gun but not pulling the trigger :)

You also need...

Me.OrderByOn = True
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top