Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

How to make it DESC in such VBA ?

Discussion in 'Information Technology' started by Martin \(Martin Lee\), Jul 28, 2006.

Tags:
  1. Martin \(Martin Lee\)

    Martin \(Martin Lee\)
    Expand Collapse
    Guest

    The following VBA is workable:

    If TypeOf Screen.PreviousControl Is TextBox Or ComboBox Then
    Me.OrderBy = Screen.PreviousControl.ControlSource
    Me.OrderByOn = True
    Endif

    MY QUESTION IS:

    I want to make the ORDER BY arranged by DESC, HOW should the VBA ?

    ( Normally, me.orderby="...... desc" can work. However the upper sentence
    without " " , so, I don't know how to do with the desc)


    Martin Lee
     
  2. Loading...

    Similar Threads Forum Date
    Sikhism Celebrating Sikhism: Thousands descend on Yuba City for festival, parade Sikh Sikhi Sikhism Nov 7, 2015
    Could this article be describing Hukam? Sikh Sikhi Sikhism Dec 14, 2014
    Gurus Adjectives to describe Guru Gobind Singh Ji History of Sikhism Apr 16, 2014
    USA Miss America crowns 1st winner of Indian descent; racist tweets flow Breaking News Sep 16, 2013
    CNN Describes Sikh Religion Sikh Sikhi Sikhism Jan 16, 2013

  3. Allen Browne

    Allen Browne
    Expand Collapse
    Guest

    That should work unless:
    - The control is unbound, or bound to an expression (starts with "=".)
    - The field name contains a space or other strange character, so you need to
    enclose the name in square brackets.
    - There is no previous control. (It happens!)
    - The form is dirty with a record that cannot be saved (e.g. required field
    missing), so the reorder cannot take place.
    - The form is unbound.
    - You forgot the space before DESC.

    Add error handling to something like this:

    With Screen.PreviousControl
    If (.ControlType = acTextBox) or (.ControlType = acComboBox) Then
    If (.ControlSource <> vbnullstring) and not (.ControlSource Like
    "=*") Then
    If Me.Dirty Then
    Me.Dirty = False
    End IF
    Me.OrderBy = .ControlSource & " DESC"
    Me.OrderByOn = True
    End If
    End If
    End With

    --
    Allen Browne - Microsoft MVP. Perth, Western Australia.
    Tips for Access users - http://allenbrowne.com/tips.html
    Reply to group, rather than allenbrowne at mvps dot org.

    "Martin (Martin Lee)" <lajitong888@21cn.com> wrote in message
    news:%23bkZsIzcGHA.1856@TK2MSFTNGP03.phx.gbl...
    > The following VBA is workable:
    >
    > If TypeOf Screen.PreviousControl Is TextBox Or ComboBox Then
    > Me.OrderBy = Screen.PreviousControl.ControlSource
    > Me.OrderByOn = True
    > Endif
    >
    > MY QUESTION IS:
    >
    > I want to make the ORDER BY arranged by DESC, HOW should the VBA ?
    >
    > ( Normally, me.orderby="...... desc" can work. However the upper
    > sentence without " " , so, I don't know how to do with the desc)
    >
    >
    > Martin Lee
    >
    >
     
  4. Dirk Goldgar

    Dirk Goldgar
    Expand Collapse
    Guest

    "Martin (Martin Lee)" <lajitong888@21cn.com> wrote in message
    news:%23bkZsIzcGHA.1856@TK2MSFTNGP03.phx.gbl
    > The following VBA is workable:
    >
    > If TypeOf Screen.PreviousControl Is TextBox Or ComboBox Then


    Actually, that code will not work. You need either this:

    If TypeOf Screen.PreviousControl Is TextBox _
    Or TypeOf Screen.PreviousControl Is ComboBox _
    Then
    ' ... do something
    End If

    or else something like this:

    Select Case Screen.PreviousControl.ControlType
    Case acTextBox, acComboBox
    ' ... do something
    End Select

    --
    Dirk Goldgar, MS Access MVP
    www.datagnostics.com

    (please reply to the newsgroup)
     

Share This Page