简体   繁体   English

访问2016 VBA命令按钮进行排序不起作用

[英]Access 2016 VBA command button to sort not working

I need help alphabetically sorting a continuous list of records on a form. 我需要按字母顺序对表单上的记录的连续列表进行排序的帮助。 Clicking button SortAZ is supposed to trigger this action. 单击按钮SortAZ应该触发此操作。

Details: tblPatients has a list of patient names and their ID numbers. 详细信息:tblPatients包含患者姓名及其ID号的列表。 When I create a form based solely on this information, a cmd button is created and works as expected. 当我仅基于此信息创建表单时,将创建一个cmd按钮并按预期工作。 I want to also allow the user to filter the list by any criteria (say they only remember the first name, but not the ID or last name). 我还希望允许用户按任何条件过滤列表(例如,他们只记住名字,而不记住ID或姓氏)。

frmPatients has a header above the Detail section. frmPatients在“详细信息”部分上方有一个标题。 I can't seem to get vba to recognize the fields in the detail section. 我似乎无法让vba识别详细信息部分中的字段。 I have tried several different combinations (see commented lines) and even renaming the Detail section. 我尝试了几种不同的组合(请参阅注释行),甚至重命名了“详细信息”部分。

 Private Sub SortAZClick()
      Me.FilterOn = False
      Me.OrderByOn = False
     'Me.LastName.SetFocus

     'Me.OrderBy = "LastName"
     'Me.OrderByOn = True
     'Me.Detail.OrderBy = "[LastName]"
     'Me.Detail!OrderBy = "LastName"
      Me.FilterResults!OrderBy = "[LastName]"

     'Me.Form.OrderBy = "LastName"
      Me.Form.OrderByOn = True
     'me.Detail!requery
      Me.Requery
End Sub

Oh the horror!!! 哦,恐怖! The problem was in the first line. 问题出在第一行。 Should have been Private Sub SortAZ_Click() Simply leaving out the underscore prevented it from doing ANYTHING. 应该是Private Sub SortAZ_Click()只需省略下划线即可阻止它执行任何操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM