访问 VBA - 具有多个字段的 OrderBy

发布于 2024-11-02 21:16:28 字数 699 浏览 0 评论 0原文

我想知道我该怎么做。实际上,我有一些子表单,通过单击标题,我希望该子表单的记录集进行排序。这是我所做的一个例子:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

走野 2024-11-09 21:16:28

当您将字符串值分配给 OrderBy 属性时,Access 可能会对其进行转换...因此不会完全存储您期望的内容。在你的情况下,我怀疑 Access 在逗号后面添加了一个空格,所以如果你在表单的代码中包含这个...

Me.OrderBy = "COU.sigle_cours,COU.num_cours"
Debug.Print "Me.OrderBy='" & Me.OrderBy & "'"

你可能会在立即窗口中看到这个...

Me.OrderBy = 'COU.sigle_cours, COU.num_cours'

实际上我不确定这就是你的问题的解释。尽管如此,我怀疑您更有可能通过模式匹配当前的 OrderBy 值而不是测试与固定字符串的精确匹配来找到乐趣。试试这样:

Private Sub sigle_cours_Label_Click()
    If (Me.OrderBy Like "*DESC*") Then
        Me.OrderBy = "COU.sigle_cours, COU.num_cours"
    Else
        Me.OrderBy = "COU.sigle_cours DESC, COU.num_cours DESC"
    End If
    Me.OrderByOn = True
End Sub

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 ...

Me.OrderBy = "COU.sigle_cours,COU.num_cours"
Debug.Print "Me.OrderBy='" & Me.OrderBy & "'"

You might see this in the Immediate Window ...

Me.OrderBy = 'COU.sigle_cours, COU.num_cours'

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:

Private Sub sigle_cours_Label_Click()
    If (Me.OrderBy Like "*DESC*") Then
        Me.OrderBy = "COU.sigle_cours, COU.num_cours"
    Else
        Me.OrderBy = "COU.sigle_cours DESC, COU.num_cours DESC"
    End If
    Me.OrderByOn = True
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文