473,385 Members | 1,309 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,385 software developers and data experts.

multi-filter ...combo box in one form

16
Hi dears
there is 8 combo box must be make filter on "RqryAnimalsRepoert"

if i choose one items from one combo box like "DamID"...and leave other "null"
the report must be make filter as "DamID" only and leave the other filter blank

...

please, see the attached file
regards
Attached Files
File Type: zip me.zip (74.1 KB, 144 views)
Aug 26 '15 #1
21 1434
Seth Schrock
2,965 Expert 2GB
You will need to use VBA to test for the combo boxes to be null to build your filter string. Sorry, I can't open the attachment at work.
Aug 26 '15 #2
SSDA
16
i did it ...by this code

Expand|Select|Wrap|Line Numbers
  1. Private Sub btnOpenreport_Click()
  2.  ' cboDamID
  3.  If IsNull(Me.cboDamID) Then
  4.  Me.Filter = "DamID=''"
  5.  Me.FilterOn = True
  6.  Else
  7.  Me.Filter = "DamID='[cboDamID]'"
  8.  Me.FilterOn = True
  9.  End If
  10.  
  11.  'cboAnimalStatus
  12.   If IsNull(Me.cboAnimalStatus) Then
  13.  Me.Filter = "AnimalStatus=''"
  14.  Me.FilterOn = True
  15.  Else
  16.  Me.Filter = "AnimalStatus='[cboAnimalStatus]'"
  17.  Me.FilterOn = True
  18.  
  19.  End If
  20. 'cboAnimalType
  21.   If IsNull(Me.cboAnimalType) Then
  22.  Me.Filter = "AnimalType=''"
  23.  Me.FilterOn = True
  24.  Else
  25.  Me.Filter = "AnimalType='[cboAnimalType]'"
  26.  Me.FilterOn = True
  27.  End If
  28.  
  29. DoCmd.OpenQuery "RqryAnimalsRepoert"
  30.  
  31. End Sub
  32.  
Aug 26 '15 #3
Seth Schrock
2,965 Expert 2GB
So you got it to work using this code, or this is the code that you tried and it isn't working?
Aug 26 '15 #4
SSDA
16
i tried this code ...but its not working
Aug 26 '15 #5
Seth Schrock
2,965 Expert 2GB
Your current code will only filter on one field because you are replacing the value in the filter each time you set it for the next combo box. Also, the references to your combo boxes were inside the double quotes so literal text cboAnimalStatus (etc.) was getting pass to the filter, not the value selected in the combo box. Try the following:
Expand|Select|Wrap|Line Numbers
  1. Private Sub btnOpenreport_Click()
  2. Dim strFilter As String
  3.  
  4.  ' cboDamID
  5.  If Not IsNull(Me.cboDamID) Then
  6.     strFilter = "DamID='" & [cboDamID] & "'"
  7.  End If
  8.  
  9.  'cboAnimalStatus
  10.   If Not IsNull(Me.cboAnimalStatus) Then
  11.     If strFilter = "" Then
  12.         strFilter = "AnimalStatus='" & [cboAnimalStatus] & "'" 
  13.     Else
  14.         strFilter = strFilter & " And AnimalStatus ='" & cboAnimalStatus & "'"
  15.     End If
  16.  End If
  17.  
  18. 'cboAnimalType
  19.   If Not IsNull(Me.cboAnimalType) Then
  20.     If strFilter = "" Then
  21.         strFilter = "AnimalType='" & [cboAnimalType] & "'"
  22.     Else
  23.         strFilter = strFilter & " And AnimalType ='" & cboAnimalType & "'"
  24.     End If
  25.  End If
  26.  
  27.  Debug.Print strFilter
  28.  
  29.  Me.Filter = strFilter
  30.  Me.FilterOn = (strFilter <> "")
  31.  
  32. DoCmd.OpenQuery "RqryAnimalsRepoert"
  33.  
  34. End Sub
Aug 26 '15 #6
SSDA
16
Sorry… what is the strcomputer
… i defined strfilter as string
…and no action
Aug 26 '15 #7
Seth Schrock
2,965 Expert 2GB
Sorry about that. I another project going on in my text editor and I didn't notice the the autocomplete had filled in the wrong thing. I also fixed some other stuff. Try it now.
Aug 26 '15 #8
SSDA
16
Until now there is no action , the query still importing all the data… and i made some modification on the code… also no responce…

You are tired with me, brother
Aug 27 '15 #9
Seth Schrock
2,965 Expert 2GB
Add the following line at line 29:
Expand|Select|Wrap|Line Numbers
  1. Debug.Print strFilter
This will output what the filter will be into the Immediate window. If you don't see the Immediate window, press Ctrl+G in the code editor and it will appear below your code.
Aug 27 '15 #10
SSDA
16
DamID='f-000000' and AnimalStatus ='alive' and AnimalType ='cheep'

this is the filter ... it is working as the first time
but if i left any combo box ... the filter will be empty and dont importing any data from the query


regards
Aug 27 '15 #11
Seth Schrock
2,965 Expert 2GB
Try leaving cboDamID blank and post back the result from the Immediate window.

Also, are you wanting the RqryAnimalsRepoert query to get this filter as well?
Aug 27 '15 #12
SSDA
16
if i leaving cboDamID blank ... the Immediate window didnt print any thing

...
Aug 27 '15 #13
Seth Schrock
2,965 Expert 2GB
Please post your code. I just tested my code and it works no matter what combination of combo boxes I use.
Aug 27 '15 #14
SSDA
16
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3.  
  4. Private Sub btnOpenreport_Click()
  5. Dim strfilter As String
  6.  
  7.  ' cboDamID
  8.  If Not IsNull(Me.cboDamID) Then
  9.  strfilter = "DamID='" & [cboDamID] & "'"
  10.   If strfilter = "" Then
  11.    strfilter = "AnimalStatus='" & [cboAnimalStatus] & "'"
  12.   End If
  13.  End If
  14.  
  15.  'cboAnimalStatus
  16.  If Not IsNull(Me.cboAnimalStatus) Then
  17.  If strfilter = "" Then
  18.  strfilter = "AnimalStatus='" & [cboAnimalStatus] & "'"
  19.  Else
  20.   strfilter = strfilter & " and AnimalStatus ='" & cboAnimalStatus & "'"
  21.  
  22.  End If
  23.  End If
  24.  
  25.  'cboAnimalType
  26.  
  27.   If Not IsNull(Me.cboAnimalType) Then
  28.  If strfilter = "" Then
  29.  strfilter = "AnimalType='" & [cboAnimalType] & "'"
  30.  Else
  31.   strfilter = strfilter & " and AnimalType ='" & cboAnimalType & "'"
  32.  
  33.  End If
  34.  End If
  35.  
  36.  Me.Filter = strfilter
  37.  Me.FilterOn = (strfilter <> "")
  38.  Debug.Print strfilter
  39.  DoCmd.OpenQuery "RqryAnimalsRepoert"
  40.  
  41. End Sub
  42.  
  43.  
Aug 27 '15 #15
Seth Schrock
2,965 Expert 2GB
Your If-Then for the cboDamID is messed up. Try re-copying my code into yours.
Aug 27 '15 #16
SSDA
16
sir .. still importing all data from the query ...
and the filter print :
AnimalStatus='alive' And AnimalType ='sheep'

note: i left the cboDamID BLANK
regards
Aug 30 '15 #17
Seth Schrock
2,965 Expert 2GB
Okay, so we have the filter working. Now, we need a way to get that filter to the query. Please post the SQL code for your query. I'm guessing that it might be simpler to just build the query string in code and then run it that way, but I can't say for sure until I see your query.
Aug 30 '15 #18
SSDA
16
please, see below
Expand|Select|Wrap|Line Numbers
  1. SELECT qAnimals.AnimalID, AnimalsStatus.AnimalStatus, AnimalsTypes.AnimalType, qAnimals.Age, qAnimals.locationID, qAnimals.fixedassets, qAnimals.AnimalSex, qAnimals.SireID, qAnimals.DamID, qAnimals.Ready, qAnimals.ReadyDate
  2. FROM AnimalsStatus INNER JOIN (AnimalsTypes INNER JOIN qAnimals ON AnimalsTypes.AnimalTypeID = qAnimals.AnimalTypeID) ON AnimalsStatus.AnimalStatusID = qAnimals.AnimalStatusID;
Sep 1 '15 #19
Seth Schrock
2,965 Expert 2GB
Please use CODE tags when post code, VBA or SQL.

Add the following between lines 38 and 39:
Expand|Select|Wrap|Line Numbers
  1. Dim strSQL As String
  2. Dim db As DAO.Database
  3. Dim qry As DAO.QueryDef
  4.  
  5. strSQL = "SELECT qAnimals.AnimalID, AnimalsStatus.AnimalStatus, " & _
  6.          "AnimalsTypes.AnimalType, qAnimals.Age, qAnimals.locationID, " & _
  7.          "qAnimals.fixedassets, qAnimals.AnimalSex, qAnimals.SireID, qAnimals.DamID, " & _
  8.          "qAnimals.Ready, qAnimals.ReadyDate " & _
  9.          "FROM AnimalsStatus INNER JOIN (AnimalsTypes INNER JOIN qAnimals ON " & _
  10.          "AnimalsTypes.AnimalTypeID = qAnimals.AnimalTypeID) ON " & _
  11.          "AnimalsStatus.AnimalStatusID = qAnimals.AnimalStatusID " & _
  12.          "WHERE " & strFilter
  13.  
  14. Set db = CurrentDb
  15. Set qry = db.QueryDefs("RqryAnimalsRepoert") 'Check spelling on this query name
  16.  
  17. qry.SQL = strSQL
  18. qry.Close
  19.  
  20. Set db = Nothing
  21. Set qry = Nothing
Note the spelling check on line 15. I copied what you had in post #15, but just double check it.
Sep 1 '15 #20
SSDA
16
My Bro..

thanks ..now it is working in my demo Database , i will apply this code in the main project and inform u the final result ...

many many thanks for your support

regards
Sep 2 '15 #21
Seth Schrock
2,965 Expert 2GB
Glad to help. Good luck on your project.
Sep 2 '15 #22

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

Similar topics

5
by: Xenophobe | last post by:
I would like to use the same form for adding new records and editing existing records. New form values are contained in $_POST. Database values are contained in an associated array. It seems to me...
8
by: Neil | last post by:
I have a very puzzling situation with a database. It's an Access 2000 mdb with a SQL 7 back end, with forms bound using ODBC linked tables. At our remote location (accessed via a T1 line) the time...
1
by: meganrobertson22 | last post by:
Hi Everyone- I am trying to use a simple macro to set the value of a combo box on a form, and I can't get it to work. I have a macro with 2 actions: OpenForm and SetValue. I can open my form,...
8
by: Zlatko Matić | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the...
1
by: meganrobertson22 | last post by:
hi everybody- what is the best way to add data from one form to another? i have 2 tables: person and contract. here are some of the fields. table: person personid (autonumber and primary...
10
by: motessa | last post by:
Hello All, I am new to Access and have been looking for answers to my problem on the internet and have not found it yet. I hope someone can give me a hint. Thanks so much. I have a form...
1
by: Robert | last post by:
I borrowed one of the forms from the MS Access Solutions database and altered it to fit my needs. The form was the 'EditProducts' form where you select a category from a combo which then populates...
6
by: Dave | last post by:
I want to put the information that the user selects in my combo boxes into a subform that lies on the same form as the combo boxes. Thanks for your help already, Dave
0
by: Gordon Padwick | last post by:
A form contains controls, one or more of which can be other forms. A form that contains another form is known as a main form. A form contained by a main form is known as a subform. A subform itself...
7
by: cliffschooling | last post by:
I've used Access for some time but nver had to use any code. Ive a problem getting combo boxes to cascade in a sub form, I've done some searches and the problem appears to be in the identifaction of...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.