Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    CoZak is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    May 2018
    Posts
    33

    Filtering a form: Making a blank filter to show all records


    Hey guys, I ve added comboboxes to a form, in order to filter a subform. However when I leave the combobox blank (I have added an option) or when no value was picked the subform is already filtered (when i open the form the subform is already filtered while comboboxes appear emtpy...), this way when i choose 1 combobox only to filter, for example age of line= 5 it doesnt show ALL records where age of line = 5 which is kinda annoying. For the filtering I used the built in macros after update event and the "SearchForRecord" action. I tried to add that when no value is selected then all filters are applied with AND (therefore no filter) but it isnt working. I ve attached a pic and the file so you can understand the issue better maybe.. I tried to use the filtering method where you filter the query directly from the criteria with the combobox is the form but then no records showed..Road_Marking_Database_51.zip
    Click image for larger version. 

Name:	last.jpg 
Views:	46 
Size:	141.1 KB 
ID:	34622

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    build the 'where' clause by cycling thru all the controls....
    it executes after a find button CLICK event
    if null, ignore.
    if not, apply.

    Code:
    '----------------
    sub btnFilter_click()
    '----------------
    dim sWhere as string 
    
    sWhere = "1=1"
    if not IsNUll(cboST) then sWhere = sWhere & " and [State]='" & cboST & "'"
    if not IsNUll(cboCity) then sWhere = sWhere & " and [city]='" & cboCity & "'"
    if not IsNUll(cboZip) then sWhere = sWhere & " and [ZipCode]='" & cboZip & "'"
    
    If sWhere = "1=1" Then
      Me.FilterOn = False
    Else
      Me.Filter = sWhere
      Me.FilterOn = True
    End If
    end sub

  3. #3
    CoZak is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    May 2018
    Posts
    33
    Hi again ranman, thanks for the help but I get the error runtime error 3464 data type mismatch. The debugger shows the line Me.FilterOn = True
    It s not related to the different data types (date, number etc) because I tried the code again with just numeric values and I still had the error.
    Also will this show all records or just revert me to the way it looks when i open the subform? Since the subform il already filtered when I open it which is weird.

    Here s the code if I made an error
    Code:
    Private Sub btn_clear_Click()
    Dim sWhere As String
    
    
    sWhere = "1=1"
    If Not IsNull(cmb_kp) Then sWhere = sWhere & " and [KP]='" & cmb_kp & "'"
    If Not IsNull(cmb_bound) Then sWhere = sWhere & " and [Bound]='" & cmb_bound & "'"
    If Not IsNull(cmb_line) Then sWhere = sWhere & " and [Line]='" & cmb_line & "'"
    If Not IsNull(cmb_applicationdate) Then sWhere = sWhere & " and [Application Date]='" & cmb_applicationdate & "'"
    If Not IsNull(cmb_age) Then sWhere = sWhere & " and [Age of line when measured]='" & cmb_age & "'"
    
    
    
    
    If sWhere = "1=1" Then
      Me.FilterOn = False
    Else
      Me.Filter = sWhere
      Me.FilterOn = True
      
    End If
    
    
    End Sub
    thanks for the help as always though

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    this code must be in the subform, not a module.
    the control sWheres in my example are all strings. you must alter for numerics.

  5. #5
    CoZak is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    May 2018
    Posts
    33
    Ok i ll try that

  6. #6
    CoZak is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    May 2018
    Posts
    33
    But how can my button be visible in a subform when it is displayed as a table?

  7. #7
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Replace Me with Me.sfrmControlName.Form (the name of your subform control) as in Me.sfrmControlName.Form.Filter = sWhere and place the code in the main form.

    Cheers,
    Vlad

  8. #8
    CoZak is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    May 2018
    Posts
    33
    Ηι vlad, thanks for the info, but how can I have a visible control in a subform displayed as a table? In Design View i can see it but in Form View no. See pic on first post, the subform is location's Rl Qd measurements

  9. #9
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    You can't (have buttons show on a datasheet form), that is why I suggested you move it to the main form. How do you apply the filter now? You need to replace the individual macros with Ranman2 code and place the button that runs it on the main form beside the combo-boxes.

    Cheers,
    Vlad

  10. #10
    CoZak is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    May 2018
    Posts
    33
    Hey Vlad thanks for the help,

    That s what I did, the code and the button is in the form, as well as the comboboxes (that work) but the filter reset button doesnt, I can see the code running (subform flickering) but nothing happens.
    Since the subform seems already filtered when i open the form even though the comboboxes are empty will "resetting" the filters work??

    CoZak

  11. #11
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Hi CoZak,

    I would add Me.sfrmControlName.Form.Filter ="" to reset the filter and a Me.sfrmControlName.Form.Requery:

    Code:
    
    If sWhere = "1=1" Then
      Me.sfrmControlName.Form.Filter =""
      Me.sfrmControlName.Form.FilterOn = False
    Else
      Me.sfrmControlName.Form.Filter = sWhere
      Me.sfrmControlName.Form.FilterOn = True
      
    End If
    Me.sfrmControlName.Form.Requery
    You could also try to turn the filter off in the OnOpen event of the subform: Me.FIlterOn = False

    Cheers,
    Vlad

  12. #12
    CoZak is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    May 2018
    Posts
    33
    Hey Vlad,

    Thanks for the continuuous help, but it looks like it s not working, it s because I used Macros with the SearchForRecord instead of a filter right?

    Regards,
    CoZak

  13. #13
    CoZak is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    May 2018
    Posts
    33
    Did I maybe do smth in order the subform to only show 5 records max?
    Why cant it search for aaaaalll records on 12/12/17 (example) and not just a batch of them?

  14. #14
    CoZak is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    May 2018
    Posts
    33
    Ok asking the question made me think, the query was also searching with the location ID which had at max 5 measurements but the ID was not shown so the query probably filtered the first result by ID ascending now this part is fixed, I ll keep trying with the filters

  15. #15
    CoZak is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    May 2018
    Posts
    33
    The problem wasnt the filter.on = False it was the Link Master Fields and Link Child Fields
    But now my graph doesnt work since before the Search Record would act on the query but now the
    Code:
    q_get_measurement_subform.Form.Filter = "[KP]= " & Str(Nz([Screen].[ActiveControl], 0))
    q_get_measurement_subform.Form.FilterOn = True
    I use only modifies the subform thus my graph doesnt change
    Any idea how the graph can refer to a subform and not a table or query?

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 02-27-2014, 08:25 PM
  2. Query wont show records with a blank field
    By bignate in forum Queries
    Replies: 2
    Last Post: 09-03-2013, 04:45 AM
  3. Replies: 4
    Last Post: 05-11-2013, 07:51 AM
  4. Replies: 12
    Last Post: 02-10-2013, 10:13 AM
  5. Replies: 1
    Last Post: 08-16-2012, 01:51 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