Solved

OrderBy

Posted on 2016-10-30
8
27 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
Comment Utility
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

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:DatabaseDek
Comment Utility
Thanks Ray

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

Accepted Solution

by:
hnasr earned 500 total points
Comment Utility
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
Comment Utility
Great thanks
0
 
LVL 30

Expert Comment

by:hnasr
Comment Utility
Welcome!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
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…
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…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

763 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

7 Experts available now in Live!

Get 1:1 Help Now