Solved

OrderBy

Posted on 2016-10-30
8
57 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
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!

 

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MS Access Subform Unique Records Issue 14 37
Save Selections in MS Access 3 31
Access #Deleted data 20 43
docmd has stopped working 3 9
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

733 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