Results 1 to 6 of 6
  1. #1
    jaryszek is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    568

    Filter field in subform using Macro

    Hi,



    i have form with subform - statuses:

    Click image for larger version. 

Name:	statusy.png 
Views:	13 
Size:	18.3 KB 
ID:	31293


    And i want to build a opening macro where filter will be set up from TempVars:

    [TempVars]("Section_name")

    How can i do it within macro?

    I am trying to write 'ZUS' manually but i failed:

    Click image for larger version. 

Name:	Macro.png 
Views:	14 
Size:	12.8 KB 
ID:	31294

    What is a syntax and why Access doesnt see my subfom field?

    Best Wishes
    Jacek

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    put a combo box on the subform, user picks an item, then it filters using the AFTERUPDATE event.
    (instead of macro, just paste this code into the EVENT PROCEDURE)

    Code:
    sub cboBox_Afterupdate()
    If IsNull(cboBox) Then
      Me.FilterOn = False
    Else
      Me.Filter = "[SectionName]='" & cboBox & "'"
      Me.FilterOn = True
    End If
    end sub

  3. #3
    jaryszek is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    568
    thank you ranman256.
    It is no possible to do it via macro without VBA?

    I want to open form with filter on it.
    And futhermore i do not want to only filter data because user can clear filter and see other values - it has to be not allowed to.

    So if Section_name is ZUS - only ZUS section should be seen by user.

    Thank you for help,
    Jacek

  4. #4
    jaryszek is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    568
    There is not possible in other way?

  5. #5
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    If it is going to be a permanent filter that cannot be changed on the form, put it in the record source of the subform. If the current record source is a table, change it to a query with this as a criteria.

  6. #6
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Instead of using a tempvar, add it as a text box on your main form, then reference that.

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

Similar Threads

  1. Replies: 2
    Last Post: 04-27-2016, 05:18 PM
  2. Replies: 3
    Last Post: 02-23-2015, 11:57 AM
  3. Combobox subform filter: text field vs. number field
    By Alhassani in forum Programming
    Replies: 2
    Last Post: 07-08-2014, 10:04 AM
  4. Replies: 1
    Last Post: 04-28-2013, 09:43 PM
  5. Macro for visible field in subform
    By g=2012 in forum Access
    Replies: 7
    Last Post: 09-11-2012, 02:23 PM

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