Order By property

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have an inquiry Form linked to a query which prompts for Criteria. I have
set the Order By Property to FieldABC but once the report opens in continuous
form view I allow the users to "re-sort" the data. I provide them with a
custom toolbar containing the Sort Ascending and Sort Descending menu items.
This all works great except...

Once the user "re-sorts" the data it overwrites my original OrderBy Property
setting. Is there a way in VB that I can reset the sort order using the
OnOpen Event? I tried to use the acCmdSortAscending but do not know how to
write VB.

Any input would be greatly appreciated.

Thanks so much for your help.

Nicole
 
Hi, Nikki.

In form design view, view properties with View, Properties and click the
square at the top left of the form to display the form's properties. Click
the Event tab, then click into the On Open field. Click the ellipsis to the
right of the field, and choose Code Builder if prompted.

Access will create the shell of a Visual Basic OnOpen event procedure.
Between the Sub and End Sub lines, enter the following code:

Me.OrderBy = "MyOrderByField"
Me.OrderByOn = True

Replace MyOrderByField with the name of the field (or fields, separated by
commas) you wish to order by, and include the quotes to make it a string
value. Save the code and the form and you're in business.

Hope that helps.
Sprinks
 
NikkiB said:
Hi,

I have an inquiry Form linked to a query which prompts for Criteria.
I have set the Order By Property to FieldABC but once the report
opens in continuous form view I allow the users to "re-sort" the
data. I provide them with a custom toolbar containing the Sort
Ascending and Sort Descending menu items. This all works great
except...

Once the user "re-sorts" the data it overwrites my original OrderBy
Property setting. Is there a way in VB that I can reset the sort
order using the OnOpen Event? I tried to use the acCmdSortAscending
but do not know how to write VB.

Any input would be greatly appreciated.

Thanks so much for your help.

Nicole

Set the form's recordsource query to sort the records initially the way
you want them. In an event procedure for the form's Open event, put
code that clears the form's OrderBy property:

'----- start of example code -----
Private Sub Form_Open(Cancel As Integer)

Me.OrderBy = ""

End Sub
'----- end of example code -----
 
Thank you so much!

That worked like a charm!

Sprinks said:
Hi, Nikki.

In form design view, view properties with View, Properties and click the
square at the top left of the form to display the form's properties. Click
the Event tab, then click into the On Open field. Click the ellipsis to the
right of the field, and choose Code Builder if prompted.

Access will create the shell of a Visual Basic OnOpen event procedure.
Between the Sub and End Sub lines, enter the following code:

Me.OrderBy = "MyOrderByField"
Me.OrderByOn = True

Replace MyOrderByField with the name of the field (or fields, separated by
commas) you wish to order by, and include the quotes to make it a string
value. Save the code and the form and you're in business.

Hope that helps.
Sprinks
 
Back
Top