访问 VBA - 具有多个字段的 OrderBy
我想知道我该怎么做。实际上,我有一些子表单,通过单击标题,我希望该子表单的记录集进行排序。这是我所做的一个例子:
Private Sub sigle_cours_Label_Click()
If (Me.OrderBy = "COU.sigle_cours") Then
Me.OrderBy = "COU.sigle_cours DESC"
Else
Me.OrderBy = "COU.sigle_cours"
End If
Me.OrderByOn = True
End Sub
我的问题是这样的:我想使用 sigle_cours 和 num_cours 进行 OrderBy 但它不起作用。我尝试这样做,但无法按 DESC 排序:
Private Sub sigle_cours_Label_Click()
If (Me.OrderBy = "COU.sigle_cours,COU.num_cours") Then
Me.OrderBy = "COU.sigle_cours DESC,COU.num_cours DESC"
Else
Me.OrderBy = "COU.sigle_cours,COU.num_cours"
End If
Me.OrderByOn = True
End Sub
我应该怎么做?
I wonder how I should do this. Actually, I have some subform and, by clicking on the title, I want the recordset of this subform to orderby. This is an example of what I do:
Private Sub sigle_cours_Label_Click()
If (Me.OrderBy = "COU.sigle_cours") Then
Me.OrderBy = "COU.sigle_cours DESC"
Else
Me.OrderBy = "COU.sigle_cours"
End If
Me.OrderByOn = True
End Sub
My problem is this one : I want to OrderBy with sigle_cours AND num_cours but it don't work. I try this but there's no way to sort by DESC :
Private Sub sigle_cours_Label_Click()
If (Me.OrderBy = "COU.sigle_cours,COU.num_cours") Then
Me.OrderBy = "COU.sigle_cours DESC,COU.num_cours DESC"
Else
Me.OrderBy = "COU.sigle_cours,COU.num_cours"
End If
Me.OrderByOn = True
End Sub
How should I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您将字符串值分配给 OrderBy 属性时,Access 可能会对其进行转换...因此不会完全存储您期望的内容。在你的情况下,我怀疑 Access 在逗号后面添加了一个空格,所以如果你在表单的代码中包含这个...
你可能会在立即窗口中看到这个...
实际上我不确定这就是你的问题的解释。尽管如此,我怀疑您更有可能通过模式匹配当前的 OrderBy 值而不是测试与固定字符串的精确匹配来找到乐趣。试试这样:
When you assign a string value to the OrderBy property, Access may transform it ... so won't exactly store what you expect. In your case, I suspect Access adds a space after the comma, so if you include this in your Form's code ...
You might see this in the Immediate Window ...
Actually I'm not positive that is the explanation for your problem. Nevertheless I suspect you're more likely to find joy by pattern-matching the current OrderBy value instead of testing for an exact match to a fixed string. Try it this way: