Results 1 to 11 of 11
  1. #1
    margzj is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Location
    Dubai
    Posts
    41

    How to apply filter from another form

    I have this code from another website but it's not working. I want to filter the split view form from another form.

    PrivateSub btnSearch_Click()

    '//Check that other form is loaded - if not, then open it
    IfNot fIsLoaded("frmMain")Then
    DoCmd
    .OpenForm ("frmMain")


    EndIf
    '//Set filter to listbox criterion
    Forms
    ("frmMain").Filter ="[Priorities] = "& Chr(34)&Me.Priorities & Chr(34)
    Forms
    ("frmMain").FilterOn =True

    EndSub

    Function fIsLoaded(ByVal strFormname AsString)AsBoolean

    'Returns False if form is not open or True if Open
    If SysCmd(acSysCmdGetObjectState, acForm, strFormname)<>0Then

    If Forms(strFormname).CurrentView <>0Then
    fIsLoaded
    =True
    EndIf

    EndIf
    EndFunction


    I received this error

    Click image for larger version. 

Name:	1.jpg 
Views:	11 
Size:	249.8 KB 
ID:	29381

    This macro is already filtering the query but is it showing all the data that has priority. [MasterQuery]![Priorities]=[Priorities]

  2. #2
    margzj is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Location
    Dubai
    Posts
    41
    Hi It's already working now, how to filter different field at the same time. I use the same code above.


    This is my form
    Click image for larger version. 

Name:	form.jpg 
Views:	10 
Size:	128.7 KB 
ID:	29382

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Not really sure why that error occurs. However, the fIsLoaded custom function is not necessary.
    Code:
    Private Sub btnSearch_Click()
    '//Check that other form is loaded - if not, then open it
    If Not CurrentProject.AllForms("frmMain").IsLoaded Then
            DoCmd.OpenForm ("frmMain")
    End If
    '//Set filter to listbox criterion
        Forms("frmMain").Filter ="[Priorities] = " & Chr(34) & Me.Priorities & Chr(34)
        Forms("frmMain").FilterOn =True
    End Sub
    This is not a macro, it is VBA procedure. Macros in Access are very different means of coding.

    Controls for the purpose of selecting filter criteria should be UNBOUND. Review http://www.allenbrowne.com/ser-62.html
    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.

  4. #4
    margzj is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Location
    Dubai
    Posts
    41
    This is the macro I am talking about "[MasterQuery]![Priorities]=[Priorities]"

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    That isn't a macro, it is just an expression. Where are you using that expression?
    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.

  6. #6
    margzj is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Location
    Dubai
    Posts
    41
    This is the macro

    Click image for larger version. 

Name:	macro.jpg 
Views:	9 
Size:	93.1 KB 
ID:	29383

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Drop the .Text property.

    Should name controls different from fields, such as tbxPriorities or cbxPriorities.

    Is MasterQuery the form's RecordSource?

    Why do you even have this macro when you have VBA procedure applying filter? Only one of them will run as determined by choice set in the OnClick event property. What is the choice?
    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.

  8. #8
    margzj is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Location
    Dubai
    Posts
    41
    Yes MasterQuery is the record source of my form. I did not put the macro and the vba together, I am experimenting on how to filter the form with multiple fields.

  9. #9
    margzj is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Location
    Dubai
    Posts
    41
    This criteria also in the query is not working
    Code:
    Is Null Or Like "*" & [Forms]![frmSearch]![cmbPriorities] & "*"
    It's showing all even the null value. But if I remove the
    Code:
    Is Null
    the filter is working fine.

    Any other option I can use? to filter multiple fields

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Review the link I referenced in post 3.
    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.

  11. #11
    margzj is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Location
    Dubai
    Posts
    41
    Quote Originally Posted by June7 View Post
    Review the link I referenced in post 3.
    Hi Priority filter is working now, thanks. How to filter by contains?

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

Similar Threads

  1. Apply a Filter to a Form
    By chaddresnick in forum Access
    Replies: 1
    Last Post: 03-26-2015, 07:37 AM
  2. Filter By Form and Apply Filter Buttons
    By JustLearning in forum Forms
    Replies: 13
    Last Post: 02-18-2015, 01:01 PM
  3. Macro to apply filter to form
    By mattzkn in forum Macros
    Replies: 3
    Last Post: 12-11-2013, 12:57 AM
  4. Replies: 2
    Last Post: 02-25-2013, 10:47 AM
  5. Replies: 5
    Last Post: 02-07-2013, 12:21 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