Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 877
  • Last Modified:

VBA, Apply Filter

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
BramJan
Asked:
BramJan
  • 3
  • 2
  • 2
  • +1
1 Solution
 
dovholukCommented:
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
 
BramJanAuthor Commented:
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
 
dovholukCommented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
BramJanAuthor Commented:
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
 
hgoyerCommented:
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
 
amp072397Commented:
BramJan:

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

thanks!
amp
community support moderator
0
 
amp072397Commented:
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
 
amp072397Commented:
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now