Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 10-20-2018, 04:17 AM   #1
basilyos
Newly Registered User
 
Join Date: Jan 2014
Posts: 210
Thanks: 56
Thanked 3 Times in 3 Posts
basilyos is on a distinguished road
Filter continuous Form

hello guys


am filtering my continuous form usin this code


Code:
Dim str1 As String

str1 = "[Sanction_Number] LIKE " & Chr(34) & "*" & Me.Search.Text & "*" & Chr(34)

Form.Filter = str1
Form.FilterOn = True
Me.Search.Value = ""
Me.Search.SetFocus

but if the result is empty and try to search something else am getting this error


you can't reference a property or method for a control unless the control has the focus


i know that the problem is when the result is empty so the controls will not appear and then i cant refer to this hidden controls


so how to solve this problem


thanks

basilyos is offline   Reply With Quote
Old 10-20-2018, 04:33 AM   #2
basilyos
Newly Registered User
 
Join Date: Jan 2014
Posts: 210
Thanks: 56
Thanked 3 Times in 3 Posts
basilyos is on a distinguished road
Re: Filter continuous Form

thank you guys i find the solution


Code:
    Dim strFilter As String
    If Len(Trim(Me.Search.Value & vbNullString)) > 0 Then
        strFilter = "Sanction_Number Like '*" & _
            Replace(Me.Search.Value, "'", "''") & _
            "*'"
        Debug.Print strFilter
        Me.Filter = strFilter
        Me.FilterOn = True
        Me.Search.Value = ""
        Me.Search.SetFocus
    Else
        Me.FilterOn = False
        Me.Search.Value = ""
        Me.Search.SetFocus
    End If
basilyos is offline   Reply With Quote
Old 10-20-2018, 06:09 AM   #3
The_Doc_Man
Happy Retired Curmudgeon
 
Join Date: Feb 2001
Location: Suburban New Orleans, LA, USA
Posts: 12,472
Thanks: 62
Thanked 1,175 Times in 1,075 Posts
The_Doc_Man is a splendid one to behold The_Doc_Man is a splendid one to behold The_Doc_Man is a splendid one to behold The_Doc_Man is a splendid one to behold The_Doc_Man is a splendid one to behold The_Doc_Man is a splendid one to behold The_Doc_Man is a splendid one to behold
Re: Filter continuous Form

Consider this:

Code:
        Me.Search.SetFocus
        Me.Search = ""
Since you get an error that TELLS you that you need to have focus on something to work with it, why would you NOT (just for safety) put the .SetFocus first. AND for any control that HAS a value, the .Value property is the default so you can omit it.

But the truth is, the value of a control is always available if it is a control that HAS a value at all, unless the control is unbound.

__________________
I'm a certified grandpa (3 times now) and proud of it.
Retired over one year and survived being home all day with the wife. She must really love me.
If I have helped you, please either click the thanks or click the scales.
The_Doc_Man is offline   Reply With Quote
The Following User Says Thank You to The_Doc_Man For This Useful Post:
basilyos (10-20-2018)
Reply

Tags
continuous form , vba

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Filter Upon Filter in Continuous Form 123dstreet Modules & VBA 6 10-02-2017 11:06 AM
[SOLVED] Filter Continuous Form mafhobb Modules & VBA 5 10-26-2015 06:31 AM
Filter Continuous Form milkman2500 Modules & VBA 1 09-17-2013 09:36 AM
Filter on continuous sub form access7 Forms 1 03-01-2012 02:35 AM
Filter a continuous form CanWest Forms 2 08-28-2011 10:47 AM




All times are GMT -8. The time now is 02:07 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Sponsored Links

How to advertise

Media Kit


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World