Access Split Form Filter

I have a split form bound to a table with a control button that will filter the table.

below is the macro builder code attached to the click event of the button.

If DCount("PLU","[tbl_Item]",[PLU] Like "*" & [Forms]![Item_Master]![SearchField] & "*")=0
Message: Item does not exist
Else
Apply Filter
Where [PLU] Like "*" & [Forms]![Item_Master]![SearchField] & "*"


The issue is:  

   the form defaults to the first record of the table and  then the filter will just looks at the first record and not the entire table.  If the "*new record" row on the bottom of the split form is selected every time the filter is run (manual mouse click) then the filter will work.  

I tried to add the code: GoToRecord new at the top of the macro.  After I did this, the filter works if I enter a value in the search box that exists in the table.  However, if a unmatched value is entered in the search box the message box function does not work: the filter will select the "*new record" bottom row, and display 1 of 1 records filtered.
tike55Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jeffrey CoachmanMIS LiasonCommented:
Not sure, ...I use VBA, ..not macros, and this code works fine for me:

Me.Filter = "PLU Like '*" &[Forms]![Item_Master]![SearchField] & "*'"
Me.FilterOn=True

But lets see if an expert can gt this going with macros...

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tike55Author Commented:
How would you add the message box if the filter does not find any matches?
tike55Author Commented:
My filter works fine by itself,  when i add the code for the message box it breaks(as stated in my original question)
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Jeffrey CoachmanMIS LiasonCommented:
Again, I don't use macros because of their limited functionality, ...but also because you can't "Copy" a macro and paste it here (word for word) for people to examine...

VBA code like this works fine for me:

If DCount("EmpCat", "[YourTable]", [EmpCat] Like "*" & [Forms]![YourForm]![Text12] & "*") = 0 Then
    msgbox "Item does not exist"
Else
    Me.Filter = "EmpCat Like '*' & [Forms]![YourForm]![Text12] & '*'"
    Me.Filter = "EmpCat Like '*' & [Forms]![YourForm]![Text12] & '*'"
    Me.FilterOn = True
End If
Jeffrey CoachmanMIS LiasonCommented:
Oh...,
...Try your Macro condition like this:

DCount("PLU","[YourTable]","[PLU] Like '*' & [Forms]![Item_Master]![SearchField]  & '*'")=0

A macro expression like this worked for me...
tike55Author Commented:
the marcro condition works.

However, I couldn't get the VBA to work (preferred)  when I enter in values into the PLU field, the all come up as "Item does not exist"
Jeffrey CoachmanMIS LiasonCommented:
It worked fine for me.

Please post a small sample database that exhibits this issue.
tike55Author Commented:
before I post...
is it possible to create a message box using the macro builder that will have a yes/no option?
tike55Author Commented:
can you send me an email? I don't want my database to be viewable
tike55Author Commented:
attached
test.accdb
tike55Author Commented:
When you type in 3013 or Link it shows up as 'item does not exist' when It clearly does in the table
Jeffrey CoachmanMIS LiasonCommented:
ok
Jeffrey CoachmanMIS LiasonCommented:
This works for me:

If DCount("PLU", "[tbl_Item]", "[PLU] Like '*' & [Forms]![Item_Master]![SearchField] & '*'") = 0 Then
     MsgBox "Item does not exist"
 Else
     Me.Filter = "PLU Like '*' & [Forms]![Item_Master]![SearchField] & '*'"
     Me.FilterOn = True
 End If

Open in new window

tike55Author Commented:
the filter doesn't work accurately with the code provided. In the sample dbase, search for 30.  then clear the filter and search for another value, the results will be incorrect.

The filter works the first time you run it, but all attempts after have inaccurate results.
Jeffrey CoachmanMIS LiasonCommented:
how are you clearing the filter?

One way is something like this:
Me.Filter=""
Me.FilterOn=False
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.