访问VBA的OpenForm分组和排序 [英] Access VBA OpenForm Grouping and Sorting

查看:325
本文介绍了访问VBA的OpenForm分组和排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个是用于数据输入的形式。我们必须通过回去数据添加到这些记录。有没有办法拉起来的形式,组通过现场的A和排序的记录是由场B?这将从根本上订购的形式A1-1,A1-2,等等,使得增加的数据更容易。

I have a form that is used for data entry. We have to go back through and add data to these records. Is there a way to pull up the form that groups the records by field "A" and sorts by field "B"? This would essentially order the forms A1-1, A1-2, etc, making adding data easier.

现在,我使用DoCmd.OpenForm与在某些领域某些值只显示记录。我只需要修改这个有点?

Right now I am using DoCmd.OpenForm to only display records with certain values in certain fields. Do I just need to modify this a bit?

感谢您的帮助!

我想这个加载按钮点击的形式,所以我有

I would like this to load the form on button click so I have

Private Sub btnDataEntry_Click() 
    DoCmd.OpenForm "Data Sheet", acNormal, , , acFormEdit, , OpenArgs:="MapNumber"
End Sub

然后当提示

Private Sub Form_Load() 
    If Not IsNull(Me.OpenArgs) Then 
        Main.OrderBy = Me.OpenArgs 
        Main.OrderByOn = True 
    End If 
End Sub

这是不是为我工作。如果可能的话我也喜欢它把所有的地图数字相加,然后让所有的项目数量上升。因此,有可能是10项与地图编号为1,项目编号1-10。

This is not working for me. If possible I would also like it to group all map numbers together and then have all Item numbers ascending. So there could be 10 entries with map number 1 and item numbers 1-10.

推荐答案

的OpenForm 不包括一个选项来指定排序顺序。然而,你可以使用它的 OpenArgs 的选项来传递某种信息,然后将该表加载过程。

OpenForm doesn't include an option to specify the sort order. However you could use its OpenArgs option to pass in sort information, then apply that during form load.

Private Sub Form_Load()
    If Not IsNull(Me.OpenArgs) Then
        Me.OrderBy = Me.OpenArgs
        Me.OrderByOn = True
    End If
End Sub

然后打开的 YourForm 的排序了一场名为 ID 的升序排列...

Then to open YourForm sorted by a field named id in ascending order ...

DoCmd.OpenForm "YourForm", OpenArgs:="id"

包括 DESC 的递减顺序...

Include DESC for descending order ...

DoCmd.OpenForm "YourForm", OpenArgs:="id DESC"

使用此版本的的Form_Load 的解决为什么形式没有你期望的排序打开。

Use this version of Form_Load to troubleshoot why the form opens without the sorting you expect.

Private Sub Form_Load()
    MsgBox "Me.OpenArgs: " & Nz(Me.OpenArgs, "Null")
    If Not IsNull(Me.OpenArgs) Then
        Me.OrderBy = Me.OpenArgs
        Me.OrderByOn = True
    End If
    MsgBox "Me.OrderBy : '" & Me.OrderBy & "'"
    MsgBox "Me.OrderByOn: " & Me.OrderByOn
End Sub

这篇关于访问VBA的OpenForm分组和排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆