Solved

VBA, Apply Filter

Posted on 2001-06-11
8
831 Views
Last Modified: 2008-02-01
Hi,

I have this annoying thing that I can't solve. I want to apply a filter (afterupdate a combo box), but it doesnot seems to work.

This is what I have:
DoCmd.ApplyFilter , "[Segment] = " & Forms!SalesfunnelSegment.Segment And "[LeadLaf].[Code] = " & Forms!LeadsLaf.Code
The error message is "Type Mismatch"

However this works:
DoCmd.ApplyFilter , "[Segment]='" & Forms!SalesfunnelSegment.Segment & "'"

It seems that I can't ask to filter on two fields, which I think should be possible.

Any ideas?

Thx in advance.

Cheers
BJ
0
Comment
Question by:BramJan
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 8

Expert Comment

by:dovholuk
ID: 6176812
right off the bat the two different filters are not the same.  my guess is that the Segment field is a string, right? if it is, that's why the second filter works and not the first. the second filter has apostrophes buffering the Segment form control, the first statement does not.

a type mismatch usually occurs when you are trying to compare "apples to orages", or Strings to Numeric data. if access is expecting a string, and instead is getting a number with no apostrophes, it'll send you the type mismatch error.

have you tried putting the apostrophes in your first filter and run it again?

dovholuk
0
 

Author Comment

by:BramJan
ID: 6176847
Hi,

You are right, but I made a mistake when showing the first function, when putting strings overthere, I still get the same message. So the function I put there is:

DoCmd.ApplyFilter , "[Segment] = '" & Forms!SalesfunnelSegment.Segment & "'" Or "[LeadLaf].[Code] '= " & Forms!LeadsLaf.Code & "'"

So that's probably not it. Any more ideas?

Thx
BJ










0
 
LVL 8

Expert Comment

by:dovholuk
ID: 6177046
first off, the

"'" Or "[LeadLaf].[Code] <--two extra quotes around Or

should probably be replaced by

"' Or [LeadLaf].[Code]  <--removed the two extra quotes

now you've got an apostrophe in a wrong spot! :)  

check

[LeadLaf].[Code] '=  <--note the apostrophe is before the equals

should be


[LeadLaf].[Code] = '  <--note the apostrophe is after the equals

does that work?  i usually don't work with filters, so i'm just throwing out ideas here on what is normally syntactically correct/incorrect...

dovholuk
0
 

Author Comment

by:BramJan
ID: 6177500
Ok, the comma stuff is not the problem....
This is how th comma's should be and he still gives the "Type Mismatch" error.

DoCmd.ApplyFilter , "[Segment] = " & "'" & Forms!SalesfunnelSegment.Segment & "'" AND "[Code] = " & "'" & Forms!LeadsLaf.Code & "'"

In this line all the comma's are correct, but still I get the error. I think he makes it a problem since there are two criterea and I don't know how to solve that.

Cheers
BJ
0
Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

 

Accepted Solution

by:
hgoyer earned 75 total points
ID: 6177893
There's still an error in that line:

DoCmd.ApplyFilter , "[Segment] = " & "'" & Forms!SalesfunnelSegment.Segment & "'" AND "[Code] = " &
"'" & Forms!LeadsLaf.Code & "'"

Try this line:

DoCmd.ApplyFilter , "[Segment] = '" & Forms!SalesfunnelSegment.Segment & "' AND [Code] = '" & Forms!LeadsLaf.Code & "'"

Helen

0
 

Expert Comment

by:amp072397
ID: 6742477
BramJan:

Another open question that needs your attention. Please address it.

thanks!
amp
community support moderator
0
 

Expert Comment

by:amp072397
ID: 6758830
It's time to clean up this topic area and that means taking care of this question. Your options at this point are:

1. Award points to the Expert who provided an answer, or who helped you most. Do this by clicking on the "Accept Comment as Answer" button that lies above and to the right of the appropriate expert's name.

2. PAQ the question because the information might be useful to others, but was not useful to you. To use this option, you must state why the question is no longer useful to you, and the experts need to let me know if they feel that you're being unfair.

3.  Ask Community Support to help split points between participating experts.  Just comment here with details.

4.  Delete the question because it is of no value to you or to anyone else.  To use this option, you must state why the question is no longer useful to you, and the experts need to let me know if they feel that you're being unfair.

If you elect for option 2, 3 or 4, just post comment with details here and I'll take it from there. We also request that you review any other open questions you might have and update/close them.  Display all your question history from your Member Profile to view details.

PLEASE DO NOT AWARD THE POINTS TO ME.
____________________________________________

Hi Experts:

In the event that the Asker does not respond, I would very much appreciate your opinions as to which Expert ought to receive points (if any) as a result of this question.  Likewise, you can also suggest that I PAQ or delete the question.

Experts, please do not add further "answer" information to this question.  I will be back in about one week to finalize this question.

Thank you everyone.

amp
community support moderator
0
 

Expert Comment

by:amp072397
ID: 6782492
BramJan:

You have several open questions:

http://www.experts-exchange.com/jsp/qShow.jsp?qid=20130128
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20244946
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20133050
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20258924

My usual script:

To assist you in your cleanup, I'm providing the following guidelines:

1.  Stay active in your questions and provide feedback whenever possible. Likewise, when feedback has not been provided by the experts, commenting again makes them receive an email notification, and they may provide you with further information. Experts have no other method of searching for questions in which they have commented, except manually.

2.  Award points by hitting the Accept Comment As Answer button located above and to the left of that expert's comment.

3.  When grading, be sure to read:
http://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp#3
to ensure that you understand the grading system here at EE. If you grade less than an A, you must explain why.

4.  Questions that were not helpful to you should be PAQ'd (stored in the database for their valuable content?even if not valuable to you) or deleted. To PAQ or delete a question, you must first post your intent in that question to make the experts aware. Then, if no experts object after three full days, you can post a zero-point question at community support to request deletion or PAQ. Please include the link(s) to the question(s).
CS:  http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
At that point, a moderator can refund your points and PAQ or delete the question for you. The delete button does not work.

5.  If you fail to respond to this cleanup request, I must report you to the Community Support Administrator for further action.

Our intent is to get the questions cleaned up, and not to embarrass or shame anyone. If you have any questions or need further assistance at all, feel free to ask me in this question or post a zero-point question at CS. We are very happy to help you in this task!


thanks!
amp
community support moderator

1/26
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now