Solved

OrderBy

Posted on 2016-10-30
8
39 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
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 119

Expert Comment

by:Rey Obrero
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
 

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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

910 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now