473,396 Members | 1,608 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

A small bit of filtering VBA code help please

There is 2 parts to this.... help with either appreciated!

I have the following 3 combo boxes to filter 3 columns of data;

Expand|Select|Wrap|Line Numbers
  1. Private Sub Combo116_AfterUpdate()
  2.     If IsNull(Me.Combo116) Then
  3.         Me.FilterOn = False
  4.     Else
  5.         Me.Filter = "BankLog = """ & Me.Combo116 & """"
  6.         Me.FilterOn = True
  7.     End If
  8. End Sub
  9.  
  10. Private Sub Combo118_AfterUpdate()
  11.     If IsNull(Me.Combo118) Then
  12.         Me.FilterOn = False
  13.     Else
  14.         Me.Filter = "Team = """ & Me.Combo118 & """"
  15.         Me.FilterOn = True
  16.     End If
  17. End Sub
  18.  
  19. Private Sub Combo154_AfterUpdate()
  20.     If IsNull(Me.Combo154) Then
  21.         Me.FilterOn = False
  22.     Else
  23.         Me.Filter = "Assigned = """ & Me.Combo154 & """"
  24.         Me.FilterOn = True
  25.     End If
  26. End Sub
  27.  

The first 2 work ok but the third gives me a Run-time error '3464': Data type mismatch in criteria expression.

Combo1 gets its selection from a list and Combo2&3 from 2 tables.

I cant see why combo 3 doesnt work?????

The second part is that they work independently of each other, ie when they update they don't consider the values in the other two combo boxes. How do I compile the code so updating from any combo box will consider all values when filtering.

In essence I just want to filter a continuous form with more than one combo box, such that blank combo boxes are not considered.

Thanks in adavance
Feb 17 '12 #1
2 1725
SOLVED for those who might need it.....
Expand|Select|Wrap|Line Numbers
  1. Private Sub Combo116_AfterUpdate()
  2.     SetFilter
  3. End Sub
  4.  
  5. Private Sub Combo118_AfterUpdate()
  6.     SetFilter
  7. End Sub
  8.  
  9. Private Sub Combo154_AfterUpdate()
  10.     SetFilter
  11. End Sub
  12.  
  13. Private Sub SetFilter()
  14.     Dim strFilter As String
  15.  
  16.     If Not IsNull(Me.Combo116) Then
  17.         strFilter = " AND BankLog = " & Chr(34) & Me.Combo116 & Chr(34)
  18.     End If
  19.     If Not IsNull(Me.Combo118) Then
  20.         strFilter = strFilter & " AND Team = " & Chr(34) & Me.Combo118 & Chr(34)
  21.     End If
  22.     If Not IsNull(Me.Combo154) Then
  23.         strFilter = strFilter & " AND Assigned = " & Me.Combo154
  24.     End If
  25.     If strFilter = "" Then
  26.         Me.FilterOn = False
  27.     Else
  28.         Me.Filter = Mid(strFilter, 6)
  29.         Me.FilterOn = True
  30.     End If
  31. End Sub
Feb 17 '12 #2
NeoPa
32,556 Expert Mod 16PB
Good code. I would do it slightly differently in that I'd use the quote character in a string normally ("'") as I've never heard a good reason for using Chr() in such circumstances, even though examples of that abound. I see you've also realised that [Assigned] is not a string field so doesn't require the quotes at all.

The last bit, where the filter properties are actually set, I would do as :
Expand|Select|Wrap|Line Numbers
  1.     Me.Filter = Mid(strFilter, 6)
  2.     Me.FilterOn = (Me.Filter > "")
You're code appears to be perfectly up to the job though :-)
Feb 18 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: kittykat | last post by:
Hi, could someone please check my code? its asking the user to enter 3 letters, and check to see if these letters exist in the text file. i know ive done something wrong. can someone fix my code...
2
by: PC User | last post by:
I found some VB code to printout a richtext field and I'm trying to adapt it to MS Access 2000. I think there might be some small changes to make the adaption between VB versions. Also my OS is...
7
by: Emmet Caulfield | last post by:
In the course of examining the code for an Internet-connected authentication server, I came across the following code (twice in one function with different constants in the "if") in a file of some...
1
by: Raj Chudasama | last post by:
i have a need to load image from URL. the image is really small (gif) and i use the following code. but the code is too slow any1 have any alternative way(S)? here is the url...
4
by: Trint Smith | last post by:
How can I improve this code please? It sometimes produces this error: "Object reference not set to an instance of an object" When I do this: strSQL = "UPDATE TBL_Items SET" & _ " item_itemnumber...
3
by: Brian Blais | last post by:
Hello, I am including at the end of this document (is it better as an attachment?) some code for a small gui dialog. Since I am quite new to this, if anyone has any suggestions for improvements...
9
by: H. Dederichs | last post by:
Hello NG, I would like to read and write Outlook PST-Files with my VB.NET application natively. Is there anyone who can help me with this issue? Since PST-Files are "also" Databases, aren't...
1
by: p byers | last post by:
Good Morning Folks I have bought and own a copy of ASPImage. Installed on my Internet server. Works like a Dream writing and saving image files containing text. My brain seems to have...
3
by: bcarlsonco | last post by:
I am currently revamping a website for a small business and there is one page giving me issues. I am doing it as a favor for a friend and am not by any means the most tech savvy on coding. There is a...
2
by: Ecot | last post by:
Hi all, I have not got any php knowledge and I have found a php code on the net and using it to send e-mail from a web html form.So far the form and the code works fine. I have the following php...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.