Sorting while using Access runtime

亡梦爱人 提交于 2020-01-24 15:48:07

问题


Here's the situation: I have a database application that the users run in Access 2003 runtime mode. I have a form that runs in Datasheet view. What I want to be able to do is allow the user to change the sort order while viewing this datasheet form. I have included the normal Access sort ascending/sort descending buttons on a custom toolbar. On my PC, with full version Access installed, these sorting buttons are enabled and I can sort.

Here's the problem: My users who run without full version of Access installed can see the buttons, but they are greyed-out/disabled.

Does anyone know of a way to enable those buttons in the run-time version of Access 2003?


回答1:


Actually the buttons should work in a datasheet view. However in a continuous form in the runtime environment they will NOT be enabled and they will not work.

The simple solution here is add a couple of your own custom buttons to that meuu bar.

Have those buttons call VBA code that simply sets the sort to ascending, or decending.

So, for the a->z buttion, change the on-action to:

=MySortDown()

(Remember to add some new buttons here, don't use the built in one says they'll be disabled - you can use the custom menu editor to copy the graphic images form the original buttons however)

And for the sort descending button, you can use:

=MySortUp()

Then in a standard code module, place the above two functions that will be called and they can be written as follows.

  Public Function mySortDown()

     Dim f    As Form
     Dim c    As Control
     Set f = Screen.ActiveForm

     Set c = f.ActiveControl

     f.OrderBy = c.ControlSource
     f.OrderByOn = True

  End Function

  Public Function mySortUp()

     Dim f    As Form
     Dim c    As Control
     Set f = Screen.ActiveForm

     Set c = f.ActiveControl

     f.OrderBy = c.ControlSource & " DESC"
     f.OrderByOn = True

  End Function

Followup:

I don’t have a reference for what works. However, during testing you can create a shortcut that allows you to test/run your code as if it is in runtime mode.

Just use:

"C:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE"
"c:\program files\RidesXP\RidesXP.mdb"  /runtime

The above is on one line in the shortcut (and a space between each line).

As for the datasheet sort buttons not working, no problem. I think it might depend on which buttons you lifted from the built-in ones. Regardless, my sample/example code should work for either case.




回答2:


Shortcut Menu

I tend to create a Custom Shortcut Menu on the Shortcut Menus toolbar with the built in Sort and Filter by Selection menu items. Then just set the text box Shortcut Menu Bar property for all controls that need to be able to sort.

The down side to this is the user needs to know to right click but it is very easy to set up for multiple forms.



来源:https://stackoverflow.com/questions/1110541/sorting-while-using-access-runtime

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!