Solved

OrderBy

Posted on 2016-10-30
8
61 Views
Last Modified: 2016-10-30
What is the correct expression  for a command button in the form header on a continuous subform ("SetsSubForm") to order the records  by IDNumber (which is a Text field if it is relevant)
0
Comment
Question by:DatabaseDek
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 30

Expert Comment

by:hnasr
ID: 41866020
Command button click event:

Me.RecordSource = "Select * from tbl Order BY ID Desc"
Me.Refresh

modify tbl, ID, Desc as needed.
Default is ascending.
0
 
LVL 75
ID: 41866044
Code behind your command button:

Me.OrderBy ="[IDNumber]"   ' OR Me.OrderBy= "IDNumber"
Me.OrderByOn = True

Descending
Me.OrderBy ="[IDNumber] DESC"   ' OR Me.OrderBy= "IDNumber DESC"
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 41866063
if that is a subform, try

me![subformcontrolName].orderby="[IDNumber]"
for descending
me![subformcontrolName].orderby="[IDNumber] Desc"

me![subformcontrolName].orderbyon=true
or

me![subformcontrolName].Form.orderby="[IDNumber]"
for descending
me![subformcontrolName].Form.orderby="[IDNumber] Desc"

me![subformcontrolName].Form.orderbyon=true
0
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 

Author Comment

by:DatabaseDek
ID: 41866074
Thanks Hnasr

Don't really know if I should post this here but previous thread a week ago has closed.

In a in a procedure that runs from the attached continuous  form.  I'm using

Me.RecordSource = "Select * from SetsQuery Order By Val(TrimNumString([DoorNumber]))"

Where setsQuery is the forms record source

I copied a function from another thread earlier

I get out of stack space.

What am I doing wrong?

Public Function TrimNumString( _
  ByVal strNumString As String, _
  Optional ByVal strDecimalChr As String, _
  Optional ByVal booAcceptMinus As Boolean) _
  As String

' Removes any non-numeric character from strNumString including hexadecimal characters.
' If strDecimalChr is specified, first occurrence of this is not removed.
' If booAcceptMinus is True, a leading or trailing minus sign is accepted.
'
' 1999-08-27. Cactus Data ApS, CPH.
' 2001-06-21. Speed optimized for large string (64 K).
' 2003-12-10. intOffset changed to lngOffset.
 
  Const cbytNeg   As Byte = 45  ' "-"
 
  Dim lngPos      As Long
  Dim lngLen      As Long
  Dim lngOffset   As Long
  Dim booDec      As Boolean
  Dim booNeg      As Boolean
  Dim bytChr      As Byte
  Dim bytDec      As Byte
  Dim strNum      As String
 
  strNumString = Trim(strNumString)
  lngLen = Len(strNumString)
  If lngLen > 0 Then
    If Len(strDecimalChr) > 0 Then
      bytDec = Asc(strDecimalChr)
    End If
    ' Create empty result string of maximum possible length.
    strNum = Space(lngLen)
   
    For lngPos = 1 To lngLen
      bytChr = Asc(Mid(strNumString, lngPos, 1))
      Select Case bytChr
        Case 48 To 57
          ' Digit.
        Case bytDec
          ' Decimal point.
          If booDec = False Then
            ' One decimal point only.
            booDec = True
          End If
        Case cbytNeg
          ' Minus sign.
          bytChr = 0
          If booAcceptMinus = True And booNeg = False Then
            If Len(Trim(strNum)) = 0 Or lngPos = lngLen Then
              bytChr = cbytNeg
              ' One minus sign only.
              booNeg = True
            End If
          End If
        Case Else
          ' Ignore any other character.
          bytChr = 0
      End Select
      If bytChr > 0 Then
        ' Append accepted character by inserting it in result string.
        lngOffset = lngOffset + 1
        Mid(strNum, lngOffset) = Chr(bytChr)
      End If
    Next
  End If
 
  ' Trim and return result string.
  TrimNumString Left(strNum, lngOffset)
End Function
0
 

Author Comment

by:DatabaseDek
ID: 41866075
Thanks Ray

Do I need the brackets around "[DoorNumber]"
0
 
LVL 30

Accepted Solution

by:
hnasr earned 500 total points
ID: 41866087
If you need to return to the same record, weather you use recordsource or other way, try:
Formrecord source based on  table: a(aid, ...)
You need to save the current id, then find the recordset bookmark and move to that record on the foem after refresh.
Private Sub Command3_Click()
    Dim cid As Integer
    cid = Me.aID
    Me.RecordSource = "Select * from a order by aid Desc"
    Me.Refresh
    Dim rs As Recordset
    Set rs = Me.RecordsetClone
    rs.FindFirst ("aid='" & cid & "'")
    Me.Bookmark = rs.Bookmark
End Sub

Open in new window

Try to open a new thread to discuss the function you asked about.
Stack space error, may be due to nesting calls of functions or subs.
0
 

Author Closing Comment

by:DatabaseDek
ID: 41866137
Great thanks
0
 
LVL 30

Expert Comment

by:hnasr
ID: 41866141
Welcome!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question