Results 1 to 9 of 9
  1. #1
    mreniff is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2020
    Posts
    41

    Capture Filter Property value for record selection

    This cmdUpdate code uses the TOP predicate value entered in TEXTBOX1 to select “scattered” records throughout a filtered list (see list Select statement below).



    Code:
    Private Sub cmdUpdate_Click()
    Dim strSQL As String
    strSQL = "UPDATE Students SET Students.UpdateGroupAdvisingApt = -1 " strSQL = strSQL & "WHERE Students.[ID] IN " strSQL = strSQL & "(SELECT TOP " & CLng(Me.Textbox1) & " [ID] FROM Students As S " strSQL = strSQL & "WHERE ((S.GroupAdvisingSessionID) is null) AND (S.Flightpath) = [Forms]![SCHEDULERFlightpath]![cboFlightPathList] " ' strSQL = strSQL & "AND (S.Session = " & Val([Forms]![SelectSessionFlightpath]![SessionCombo] & "") & "));" fExecuteQuery strSQL, dbFailOnError
    Me.Textbox1 = Null
    DoCmd.Requery
    End Sub


    Form Select statement:

    Code:
    SELECT Students.Major, Students.UpdateGroupAdvisingApt, [Last] & ", " & [First] AS StudentName, Students.ID, Students.Session, Students.FlightPath, Students.GroupAdvisingSessionID, Students.SSN
    FROM [Group Advising] RIGHT JOIN Students ON [Group Advising].GroupAdvisingRecordID = Students.GroupAdvisingSessionID
    WHERE (((Students.Session)=[Forms]![SelectSessionFlightpath]![SessionCombo]) AND ((Students.FlightPath)=[Forms]![SCHEDULERFlightpath]![cboFlightPathList]) AND ((Students.GroupAdvisingSessionID) Is Null))
    ORDER BY Students.Major, Students.UpdateGroupAdvisingApt;
    Usually an additional filter is manually applied using a list attribute (e.g. [Major]) changing form’s Order By property to (e.g Forms!(StudentsByFlightPath].[Major]=”BI”).

    Is there a way to only select from the additional filtered list?

    Will an Order BY clause select from additional filtered list?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    [Forms]![SCHEDULERFlightpath]![cboFlightPathList] is not concatenated - is query working?

    If filter criteria is not included in the SQL statement, how would you expect it to be applied?

    Can reference form Filter property to include that criteria in SQL statement.

    A TOP N query usually does have ORDER BY clause. The form's sorting has no bearing on the constructed SQL statement.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    mreniff is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2020
    Posts
    41

    How to add Order by clause



    [Forms]![SCHEDULERFlightpath]![cboFlightPathList] is not concatenated - is query working? YES

    If filter criteria is not included in the SQL statement, how would you expect it to be applied? Access Sort & Filter menu commands select and "toggle" a filter I usually right click on value and select "EQUALS = [attribute value].

    Can reference form Filter property to include that criteria in SQL statement. This is what i am trying to figure out. Once an "adhoc" filter is applied, the "dynamic syntax" is visible in the form's filter property.

    A TOP N query usually does have ORDER BY clause. Order by clauses are usually the last clause in a SQL statement. Do I insert it at the end?

    The form's sorting has no bearing on the constructed SQL statement. I understand this.
    I am not sure what I am doing wrong. I keep getting the message my reply is short by ten charactoers

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    Exactly what is issue? How to reference form Filter property?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    mreniff is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2020
    Posts
    41
    Quote Originally Posted by June7 View Post
    Exactly what is issue? How to reference form Filter property?
    [quote]
    I apologize for not making myself clear and confusing two different form properties, Filter and Orderby.

    Upon applying a filter to a form, the filter value of the form changes to reflect the "adhoc or dynamic" filtering value. For lack of better wording, due to lack of programming skills, I want to capture the "dynamic" value that is in the Filter property to use in the record selection process.

    Click image for larger version. 

Name:	filter property.JPG 
Views:	9 
Size:	42.6 KB 
ID:	41790

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    Something like:

    strF = Me.Filter
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    mreniff is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2020
    Posts
    41

    me.filter

    Quote Originally Posted by June7 View Post
    Something like:

    strF = Me.Filter


    Duh! I am ashamed I did not think of that


    Next question.... Do I add me.filter with this clause strSQL = strSQL & "ORDER BY [me.filter]);?

  8. #8
    mreniff is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2020
    Posts
    41

    run time error 3137 missing semicolon at end of SQL statement

    quote]

    there is a semicolon at the end of the SQL statement. What am I missing?
    [/quote]


    Code:
    Private Sub cmdUpdate_Click()
    Dim strSQL As String
    
    
    strSQL = "UPDATE Students SET Students.UpdateGroupAdvisingApt = -1 "
    strSQL = strSQL & "WHERE Students.[ID] IN "
    strSQL = strSQL & "(SELECT TOP " & CLng(Me.Textbox1) & " [ID] FROM Students As S " ' select # or records based textbox1 value
    strSQL = strSQL & "WHERE ((S.GroupAdvisingSessionID) is null) AND (S.Flightpath) = [Forms]![SCHEDULERFlightpath]![cboFlightPathList] " '
    strSQL = strSQL & "AND (S.Session = " & Val([Forms]![SelectSessionFlightpath]![SessionCombo] & "") & "))"
    strSQL = strSQL & "ORDER BY me.filter;"
     
     fExecuteQuery strSQL, dbFailOnError
       
    ' reset textbox to blank
    Me.Textbox1 = Null
    DoCmd.Requery
    End Sub
    [

  9. #9
    mreniff is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2020
    Posts
    41
    HOt damn.... got this to work

    Code:
    rivate Sub cmdUpdate_Click() 'scheduler flightpath advising
    Dim strSQL As String
    
    
    strSQL = "UPDATE Students SET Students.UpdateGroupAdvisingApt = -1 "
    strSQL = strSQL & "WHERE Students.[ID] IN "
    strSQL = strSQL & "(SELECT TOP " & CLng(Me.Textbox1) & " [ID] FROM Students As S " ' select # or records based textbox1 value
    strSQL = strSQL & "WHERE ((S.GroupAdvisingSessionID) is null) AND (S.Flightpath) = [Forms]![SCHEDULERFlightpath]![cboFlightPathList] " '
    strSQL = strSQL & "AND (S.Session = " & Val([Forms]![SelectSessionFlightpath]![SessionCombo] & "") & ")"
    strSQL = strSQL & "ORDER BY (S.major));"
     
     fExecuteQuery strSQL, dbFailOnError
       
    ' reset textbox to blank
    Me.Textbox1 = Null
    DoCmd.Requery
    End Sub

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

Similar Threads

  1. Replies: 9
    Last Post: 02-24-2015, 11:19 AM
  2. Replies: 8
    Last Post: 01-31-2015, 11:34 AM
  3. Replies: 1
    Last Post: 10-25-2012, 12:58 PM
  4. Replies: 1
    Last Post: 08-01-2012, 03:56 PM
  5. Replies: 28
    Last Post: 03-08-2012, 06:47 PM

Tags for this Thread

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