Results 1 to 9 of 9
  1. #1
    chalupabatman is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Aug 2016
    Posts
    114

    AfterUpdate() Event To Filter Sub Form

    I have a sub form that by default loads with all OS avaliable. I have added a combo box to the main form with all 4 options of OS that will display, I want the user to be able to select an OS from the combo box and the sub-form auto-filter to that selected OS.



    I have this syntax - but I get a dialog box asking me to input the OS so it seems that I have not properly passed the value from the combo box to the procedure? How should I set this up so it functions as I desire?

    Code:
    Private Sub cboFilterStat_AfterUpdate()
    	On Error GoTo Proc_Error
    	If IsNull(Me.cboFilterStat) Then
    	   Me.[_Test].Form.Filter = ""
    	   Me.[_Test].Form.FilterOn = False
    	Else
    	  Me.[_Test].Form.Filter = "[OS]=" & Me.cboFilterStat
    	  Me.[_Test].Form.FilterOn = True
    	End If
    	Proc_Exit:
    	   Exit Sub
    	Proc_Error:
    	   MsgBox "Error " & Err.Number & " in setting subform filter:" & vbCrLf & Err.Description
    	   Resume Proc_Exit
    End Sub

  2. #2
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    You can link the subform to the main form using the OS, no code is required.

  3. #3
    chalupabatman is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Aug 2016
    Posts
    114
    @aytee111 - how would I do such?

  4. #4
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    In design view, with the property sheet open, click on the subform to bring up the properties of the subform. There will be two link fields, master and child. Type in the name of the combobox for the master link and the corresponding name of the field on the subform for the child link. The field on the subform will be a one-to-one match with the first column in the combobox's row source.

  5. #5
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,471
    You might need full path of subform so maybe if the value is text(change the path to be what it really is):

    Forms![frmMain]![_Test].Form.Filter = "OS = '" & Me.cboFilterStat & "'"
    Forms![frmMain]![_Test].Form.FilterOn = True

    the quote part is OS = single double &
    Me.cboFilterStat & double single double

  6. #6
    chalupabatman is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Aug 2016
    Posts
    114
    @aytee111 - i do not see the two link field when I pull up the Property Sheet of the form. Any idea which "Tab" they would be under, format, data, event, other ?

  7. #7
    chalupabatman is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Aug 2016
    Posts
    114
    @bulzie - that was it exactly! Good catch on that

  8. #8
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Not the form, the subform object - click once on the subform to bring up its properties. And no, I only use the All tab! They are near the top.

  9. #9
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,471
    Using linkmaster and linkchild is a good way also to filter with no code as aytee111 posted. And also another way, you could go into the Record Source query of the subform(if it is a table make it a query of the table) and in the OS field in criteria, put the path to the combo box on the main form. Then in the After Update in the comob box on main form, Requery the subform with: Forms![frmMain]![_Test].Requery

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

Similar Threads

  1. Replies: 4
    Last Post: 10-29-2014, 03:49 PM
  2. Replies: 2
    Last Post: 06-09-2012, 01:56 AM
  3. Form AfterUpdate Event
    By RayMilhon in forum Forms
    Replies: 2
    Last Post: 09-09-2011, 09:20 AM
  4. AfterUpdate event help
    By 10 Gauge in forum Forms
    Replies: 11
    Last Post: 09-08-2011, 10:04 AM
  5. how to created afterupdate event
    By Brigitt in forum Forms
    Replies: 2
    Last Post: 02-15-2011, 03:23 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