Results 1 to 3 of 3
  1. #1
    JimO is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Dec 2015
    Posts
    126

    Add ORDER BY to Code

    I am trying to add an 'ORDER BY' clause to my code with no success. The code is as follows,


    Code:
    Private Sub RequeryForm()
        Dim W As String
        Dim S As String
       W = ""
        
        If Not IsNull(StartDate) Then
            If W <> "" Then W = W & " AND "
            W = W & "EventDay >= #" & StartDate & "#"
        End If
        If Not IsNull(EndDate) Then
            If W <> "" Then W = W & " AND "
            W = W & "EventDay <= #" & EndDate & "#"
            Me.lblTimer.Caption = "All Items"
        End If
        If IsTimer = True Then
            If W <> "" Then W = W & " AND "
            W = W & "Timer = True"
            Me.lblTimer.Caption = "On Timer"
         ElseIf IsTimer = False Then
             If W <> "" Then W = W & " AND "
            W = W & "Timer = False"
            Me.lblTimer.Caption = "Off Timer"
         
        End If
           
        S = "Select * FROM CalendarTbl"
        If W <> "" Then S = S & " WHERE " & W
        
        Me.RecordSource = S
            
    End Sub
    I would like to add Order By [EventDay] but every thing I has tried so far has not worked. Any ideas would be wonderful.

    Thanks
    Jim O

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    how about

    Me.RecordSource = S & " ORDER BY [EventDay]"

  3. #3
    JimO is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Dec 2015
    Posts
    126
    Perfect. Thank you very much.

    Jim O

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 03-07-2016, 05:02 PM
  2. Replies: 5
    Last Post: 07-28-2014, 10:20 AM
  3. Changing order by using code
    By FRAZ in forum Queries
    Replies: 4
    Last Post: 01-22-2014, 12:54 PM
  4. vba code running in wrong order??
    By Paintballlovr in forum Programming
    Replies: 3
    Last Post: 08-30-2013, 03:53 PM
  5. Replies: 8
    Last Post: 01-30-2012, 02:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums