473,418 Members | 2,063 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,418 software developers and data experts.

Filtering a ACCESS Form using VBA problem empty fields

2
Hi All,

I have a continuous form with all records. For each field there is a combo in the form header and the form also contains a Toggle button "Apply Filter".
When clicked, it changes to "Cancel Filter".
Then an SQL string with condition meeting the criteria input in the combo boxes is built.

I have noticed that when certain fields are not filled in (no space, nothing), the record is simply not shown. The empty field is not necessarily one with a criteria.

Here goes the (simplified) code:
Expand|Select|Wrap|Line Numbers
  1. Select Case Me.ToggleApplyFilter.value 'check whether clicked?
  2. Case True
  3.     Me.ToggleApplyFilter.Caption = "Cancel filter"
  4.     strSQL = "SELECT CustomerComplaintForm.* FROM CustomerComplaintForm WHERE ("
  5. 'ID
  6.     If Len(Trim(Me.cboIdFilter.value)) = 0 Or IsNull(Me.cboIdFilter) Then
  7.         strComplaintIDCondition = "((CustomerComplaintForm.ComplaintId) Like '*') AND "
  8.     Else
  9.         strComplaintIDCondition = "((CustomerComplaintForm.ComplaintId) =[Forms]![FM_Customer_Complaints_List]![cboIdFilter]) AND "
  10.     End If
  11. 'Customer (Name)
  12.     If Len(Trim(Me.cboCustomerFilter.value)) = 0 Or IsNull(Me.cboCustomerFilter) Then
  13.         strCustomerCondition = "((CustomerComplaintForm.CustomerName) Like '*') AND "
  14.     Else
  15.         strCustomerCondition = "((CustomerComplaintForm.CustomerName) =[Forms]![FM_Customer_Complaints_List]![cboCustomerFilter]) AND "
  16.     End If
  17.     If Len(Trim(Me.cboProductDestinationFilter.value)) = 0 Or IsNull(Me.cboProductDestinationFilter) Then
  18.         strProductDestinationCondition = "((CustomerComplaintForm.ProductDestination) Like '*')"
  19.     Else
  20.         strProductDestinationCondition = "((CustomerComplaintForm.ProductDestination) =[Forms]![FM_Customer_Complaints_List]![cboProductDestinationFilter])"
  21.     End If
  22.  
  23.     strSQL = strSQL & strComplaintIDCondition & strCustomerCondition & strUnitsCondition & _
  24.     strPFICondition & strPOCondition & strCustRefCondition & strAcceptableCondition & _
  25.     strCauseCondition & strCategoryCondition & strSubCategoryCondition & _
  26.     strProductDestinationCondition & ");"
  27. Case False
  28.     Me.ToggleApplyFilter.Caption = "Apply filter"
  29.     strSQL = "SELECT CustomerComplaintForm.* FROM CustomerComplaintForm;"
  30.     Me.cboAcceptableFilter.value = ""
  31.     Me.cboIdFilter.value = ""
  32.     Me.cboCustomerFilter.value = ""
  33.     Me.cboCustRefFilter.value = ""
  34.     Me.cboPFIFilter.value = ""
  35.     Me.cboPOFilter.value = ""
  36.     Me.cboUnitsFilter.value = ""
  37.     Me.cboCauseFilter.value = ""
  38.     Me.cboCategoryFilter = ""
  39.     Me.cboSubCategoryFilter = ""
  40. End Select
  41.  
  42. Debug.Print strSQL
  43. Me.RecordSource = strSQL
  44.  
  45.  

Imagine the field [customer] is empty for a certain record and I only filter on [Product destination]. Well, this record with empty field [customer] will not be in the query.
I already copied the resulting SQL string in an empty query. In design view it gives
Expand|Select|Wrap|Line Numbers
  1.  Like '*' 
for all fields for which no criteria was provided in the forms. But the result is the same - wrong. When I deleted this
Expand|Select|Wrap|Line Numbers
  1.  Like '*' 
, it gave the correct result. Is there a reason why those fields are excluded?

I adjusted the SQL building so that only the non empty combo's are included in the SQL string. That way there is no
Expand|Select|Wrap|Line Numbers
  1.  Like '*' 
any more.
And it works.

It's nice it works, but I want to understand why this access behaviour?
Jan 22 '08 #1
1 6183
MMcCarthy
14,534 Expert Mod 8TB
Have a look at this tutorial and see if it helps ...

http://www.thescripts.com/forum/thread762181.html
Feb 4 '08 #2

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

Similar topics

3
by: Jason | last post by:
I am trying to filter records in a primary form based on records in related tables. The data in the related tables is being displayed in the primary form through subforms. To be more specific, I...
0
by: Keith Shearer | last post by:
I'm having a bit of trouble, moving between controls, when filtering on a form. I'm using a continuous form. At the top I have 2 date fields. I want to filter the data specified between the two...
4
by: Doug | last post by:
I have your typically form/subform. You enter the account number in a textbox and select whether you want to see the detail or summary information on the main form. Both fields I want to filter...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
0
by: Patrick | last post by:
I'm working on a contact management application, and need a hand with one aspect... Here's what I want to create: ------------------------------------ A form split into two parts. There is a...
3
by: Damon Grieves | last post by:
Hi I have a large table which I wanted to filter and then edit the selected record. I'm using a form with several pull down fields linked to lookup tables which correspond to fields in the large...
2
by: Katie | last post by:
I need to store a history of two fields in two seperate tables: Event - where the key is Event_ID Stage - where the key is Stage_ID The joins are: Main Table Event Table Stage Table ...
2
NeoPa
by: NeoPa | last post by:
CHAPTER 1 - TABLE OF CONTENTS (Including attached database) CHAPTER 2 - INTRODUCTION CHAPTER 3 - TABLE LAYOUT CHAPTER 4 - FORM LAYOUT CHAPTER 5 - FORM MODULE CHAPTER 6 - CODE DISCUSSION (FILTER...
0
by: Yarik | last post by:
Hello, Here is a sample (and very simple) code that binds an Access 2003 form to a fabricated ADO recordset: ' Create recordset... Dim rs As ADODB.Recordset: Set rs = New ADODB.Recordset '...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.