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

How to program a command button that could simultaneously filter two fields?

I require a command button that will filter my subform simultaneoulsy in two fields ( Name and Date of Registration).
(i) One field(Name) will be bounded to a combobox
(ii) Second field(Date of Registration) will be bounded to two text boxes in which the user should be allowed to enter the date range

And On click of the command button the two filter conditions should be effected
Attached Files
File Type: zip Done.zip (31.9 KB, 118 views)
Aug 21 '13 #1

✓ answered by ADezii

@aanfalsha:
We normally do not look at Attachments except when all other Options have been exhausted, but I will make an exception here. I'll post the general guidlines, and leave the rest to you.
  1. Add 2 Unbound Text Boxes to your Form named txtStart and txtFinish. These 2 Text Boxes will contain the Start and Finish Dates for the Range within which [DateV] must fall, as well as having the assigned Priority.
  2. The Code will perform 'minimal validation' in the sense that it will check for NULL Values in all 3 Fields.
  3. It will then check and see if any Records exist matching the Compound Criteria.
  4. Assumin Records were found, it will then modify the Record Source of the Sub-form reflecting those Criteria.
    Expand|Select|Wrap|Line Numbers
    1. Dim strSQL As String
    2.  
    3. With Me
    4.   If IsNull(![Combo]) Or IsNull(![txtStart]) Or IsNull(![txtFinish]) Then Exit Sub
    5. End With
    6.  
    7. strSQL = "SELECT * FROM base WHERE [Priority] = '" & Me![Combo] & "'" & _
    8.          " AND [DateV] BETWEEN #" & Me![txtStart] & "# AND #" & Me![txtFinish] & "#"
    9.  
    10. 'Do any Records matching the Criteria even exist?
    11. If DCount("*", "Base", Mid$(strSQL, InStr(strSQL, "WHERE") + 6)) = 0 Then
    12.   MsgBox "No Records found matching Criteria", vbExclamation, "No Records"
    13.     Exit Sub
    14. End If
    15.  
    16. Me!subform.Form.RecordSource = strSQL
    17.  
  5. Any questions at all feel free to ask.

4 2057
ADezii
8,834 Expert 8TB
In the Click() Event of the Command Button, you could dynamically modify the RecordSource of the Sub-Form based on the Values present in the Combo (Name) and Text (Start/End Dates) Boxes, something similar to:
Expand|Select|Wrap|Line Numbers
  1. Dim strSQL As String
  2.  
  3. strSQL = "SELECT * FROM <Data Source> WHERE [Name] = '" & Me![cboName] & "' AND " & _
  4.          "[Date of Registration] Between #" & Me![txtStartDate] & "# AND #" & _
  5.          Me![txtEndDate] & "#;"
  6.  
  7. With Me![<Sub-Form Name>]
  8.   .Form.RecordSource = "Order Details Extended"
  9.    .Requery
  10. End With
Aug 21 '13 #2
NeoPa
32,556 Expert Mod 16PB
The Filter of a recordset is equivalent to the WHERE clause in SQL (but without the WHERE keyword).

The WHERE clause typically looks like :
Expand|Select|Wrap|Line Numbers
  1. WHERE (condition1) AND (condition2) OR (condition3)
Each condition can be anything but is generally a comparison of two values, again generally, at least one will depend on a field reference.

Thus, a common Filter might be like :
Expand|Select|Wrap|Line Numbers
  1. WHERE ([Field1]='A value') AND ([Field2]='Another value')
For more on filtering see Cascaded Form Filtering
Aug 21 '13 #3
Dear ADezii

Sincere Thanks For your kind and prompt response.
Now to make things more clear I'm sending you a file in which there is a filter option assigned to a combo box for the field " priority"...Now just help me to also filter the field " DateV" allowing the user to enter the date range into two text boxes and then simultaneously selecting priority....

And Finally wher the user will be able to view the Priority during a particular period.

Hoping your kind support always and awaiting your kind response

NB:-Please find the attached file under my post
Aug 22 '13 #4
ADezii
8,834 Expert 8TB
@aanfalsha:
We normally do not look at Attachments except when all other Options have been exhausted, but I will make an exception here. I'll post the general guidlines, and leave the rest to you.
  1. Add 2 Unbound Text Boxes to your Form named txtStart and txtFinish. These 2 Text Boxes will contain the Start and Finish Dates for the Range within which [DateV] must fall, as well as having the assigned Priority.
  2. The Code will perform 'minimal validation' in the sense that it will check for NULL Values in all 3 Fields.
  3. It will then check and see if any Records exist matching the Compound Criteria.
  4. Assumin Records were found, it will then modify the Record Source of the Sub-form reflecting those Criteria.
    Expand|Select|Wrap|Line Numbers
    1. Dim strSQL As String
    2.  
    3. With Me
    4.   If IsNull(![Combo]) Or IsNull(![txtStart]) Or IsNull(![txtFinish]) Then Exit Sub
    5. End With
    6.  
    7. strSQL = "SELECT * FROM base WHERE [Priority] = '" & Me![Combo] & "'" & _
    8.          " AND [DateV] BETWEEN #" & Me![txtStart] & "# AND #" & Me![txtFinish] & "#"
    9.  
    10. 'Do any Records matching the Criteria even exist?
    11. If DCount("*", "Base", Mid$(strSQL, InStr(strSQL, "WHERE") + 6)) = 0 Then
    12.   MsgBox "No Records found matching Criteria", vbExclamation, "No Records"
    13.     Exit Sub
    14. End If
    15.  
    16. Me!subform.Form.RecordSource = strSQL
    17.  
  5. Any questions at all feel free to ask.
Aug 22 '13 #5

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

Similar topics

2
by: Darren | last post by:
Hi, I have a command button which has a macro running in it. The macro on the click event, runs to ensure that certain values in a form are valid, (e.g. the textboxes are not null) and...
2
by: John Smith | last post by:
How can I use a transparent command button to change a checkbox? I have my records set up in a continuous form and I want theuser to be able to click on the record and have this toggle the...
3
by: afr0ninja | last post by:
Hello! I'm currently working on a form that has several input fields and a subform. What I'm trying to accomplish is that when I first open the form I'd like to have the input fields displayed...
3
by: chris | last post by:
I have a form det-up as a continous form. In the Header of the form I have a command button called "Approve". What I'm looking to do is when the user clicks the command button all of the records...
5
by: mdpems | last post by:
The organization I work for needs to use a form that we can send to a billing department that shows supplies we used and Mission#'s. I have a form to select supplies used and total the costs of...
7
by: pushrodengine via AccessMonster.com | last post by:
I have a command button “AddIncident”. I would like to make it so that it will not add the record to the database if textbox “Type” is empty. I also would like to add a message that will...
2
rsmccli
by: rsmccli | last post by:
Hello. Using Access 2002. I have set up a command button on a form that will print off a list of hyperlinked documents that resides in one of our tables. I have been using code borrowed from Graham R...
3
by: KrazyKasper | last post by:
I created two Command buttons in a form, one to preview the entire report and one to "cancel" or exit the form. They both work. I'm trying to create a third Command button to select/filter data from...
5
by: Kat7 | last post by:
Hello out there! I've turned into an internet junkie trying to find the answer to this seemingly simple question. Every suggestion I try has failed. Form wizard, VBA, macros, modules ... I never...
3
by: cambar | last post by:
I created a simple macro to open a form with several command buttons on the form. On one of these buttons I want to require a password for access. I am not a programmer. What do I need to do to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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.