473,511 Members | 16,252 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need 2nd & 3rd combo box for date & status filter

5 New Member
Hi All,

I have tried different samples of combo box and still unable to finalize my form:

First let me tell you what I got and what I need:

On an unbound form I have created a subform [frmMaster_sub] from MASTERLIST QUERY. This QUERY contains
SNAME, LPODate, QTY, UNIT PRICE, AMOUNT and STATUS.

On the FORM (frmStatus) I Have created an unbound Combo boxe:
COMBO – Created created from value list

The idea is from [COMBO] I can select a particular SUPPLIER and it will list all the the purchases for the specific supplier, then I would like to add another 2 combos for date and status. wherein if I select a particular Date and status from a combo box then it will show all purchase with the same Date and status for the supplier.

So far I'm having the following vb code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command2_Click()
  2. If (Eval("[Forms]![frmStatus]![Combo] Is Null")) Then
  3.    MsgBox "Please select value first", vbOKOnly, "No Selection"
  4. ElseIf (Eval("[Forms]![frmStatus]![Combo] Is Not Null")) Then
  5. strSQL = "Select * from MASTERLIST where"
  6. strSQL = strSQL & " SNAME=" & "Forms!frmStatus!Combo"
  7. Me!frmMaster_sub.Form.RecordSource = strSQL
  8. End If
  9. End Sub
  10.  
  11.  
  12. Private Sub Command3_Click()
  13. strSQL = "Select * from MASTERLIST"
  14. Me!frmMaster_sub.Form.RecordSource = strSQL
  15.  
  16. End Sub

This works perfectly, where I am stuck now is how do I do the second & third filter. Any guidance would be greatly appreciated.


Thanks,

Rogue
Aug 11 '13 #1
11 1499
jimatqsi
1,271 Recognized Expert Top Contributor
Rogue0801, I often do something like this. What I suggest you do is to make a subroutine (mine is usually called FilterForm()) that you call in the AfterUpdate event of all 3 of these combo boxes. FilterForm will build a SQL string; really it builds a WHERE string to add to the SQL string you show in Command3_Click(), and then plug the SQL into RecordSource as you show above.

This is a very simple strategy for easily adding any number of filters. You can require any combination of the filters to be filled in or not. All the work gets done in FilterForm(), all the filters just call it in the AfterUpdate event.

Jim
Aug 11 '13 #2
jimatqsi
1,271 Recognized Expert Top Contributor
Also, Rogue0801, pay attention to your object names. Command2 and Command3 might be meaningful names for your buttons, but there might be a better name you can use for each of those. As the number of forms and objects grow in your database, you'll appreciate if your code talks to you a little more clearly about where a function comes from, what object it represents.
Aug 11 '13 #3
Rogue0801
5 New Member
Dear jimatqsi,

Appreciate your kind revert, however if it's not that much to ask, would you please help me establish your suggestion in my database? Apology for that as not that much knowledgeable in VB nor access...I have attached here my sample database for your reference.


Many Thanks,

Rogue :)
Attached Files
File Type: zip LPOh.zip (93.6 KB, 199 views)
Aug 11 '13 #4
jimatqsi
1,271 Recognized Expert Top Contributor
I won't write the code for you but I'll give you an example from one of my live applications. This is in an inventory table maintenance program. There are 8 potential filters that may or may not be filled in.
Here's the code
Expand|Select|Wrap|Line Numbers
  1. Private Sub FilterForm()
  2.  
  3.    On Error GoTo FilterForm_Error
  4.    If Me.Dirty Then Me.Dirty = False
  5.  
  6.  
  7. strSQL = "SELECT dbo_CI_Item.ItemCode, dbo_CI_Item.PriceCode, dbo_CI_Item.ProductLine, dbo_CI_Item.UDF_STATUS, dbo_CI_Item.UDF_BRAND, " & " dbo_CI_Item.UDF_FREE_FREIGHT_LEVEL,UDF_F2_COST, " & _
  8.         " dbo_CI_Item.UDF_E2_PRICE, dbo_CI_Item.DateUpdated, dbo_CI_Item.UserUpdatedKey, UseInSO, UseInPO , dbo_CI_Item.UDF_CASE_PACK, dbo_CI_Item.UDF_CARTON_PACK, " & _
  9.         " dbo_CI_Item.UDF_MAP, dbo_CI_Item.StandardUnitCost, dbo_CI_Item.StandardUnitPrice " & _
  10.         " FROM dbo_CI_Item " & " where 1=1 " & "ORDER BY dbo_CI_Item.ItemCode "
  11.  
  12. If Len(Nz(Me.SKU_filter)) > 0 Then
  13.     strSQL = Replace(strSQL, "1=1", "1=1 and ItemCode like '[itemcode]%'")
  14.     strSQL = Replace(strSQL, "[itemcode]", Me.SKU_filter)
  15. End If
  16.  
  17. If Len(Nz(Me.PriceCode_filter)) > 0 Then
  18.     strSQL = Replace(strSQL, "1=1", "1=1 and PriceCode='[PriceCode]'")
  19.     strSQL = Replace(strSQL, "[PriceCode]", Me.PriceCode_filter)
  20. End If
  21.  
  22. If Len(Nz(Me.ProductLine_filter)) > 0 Then
  23.     strSQL = Replace(strSQL, "1=1", "1=1 and ProductLine='[ProductLine]'")
  24.     strSQL = Replace(strSQL, "[ProductLine]", Me.ProductLine_filter)
  25. End If
  26.  
  27. If Len(Nz(Me.Brand_filter)) > 0 Then
  28.     strSQL = Replace(strSQL, "1=1", "1=1 and UDF_BRAND like '[UDF_BRAND]%'")
  29.     strSQL = Replace(strSQL, "[UDF_BRAND]", Me.Brand_filter)
  30. End If
  31.  
  32. If Len(Nz(Me.Status_filter)) > 0 Then
  33.     strSQL = Replace(strSQL, "1=1", "1=1 and UDF_STATUS='[UDF_STATUS]'")
  34.     strSQL = Replace(strSQL, "[UDF_STATUS]", Me.Status_filter)
  35. End If
  36.  
  37. If Len(Nz(Me.FreeFreight_filter)) > 0 Then
  38.     strSQL = Replace(strSQL, "1=1", "1=1 and UDF_FREE_FREIGHT_LEVEL='[UDF_FREE_FREIGHT_LEVEL]'")
  39.     strSQL = Replace(strSQL, "[UDF_FREE_FREIGHT_LEVEL]", Me.FreeFreight_filter)
  40. End If
  41.  
  42. If Len(Nz(Me.UseInSO_filter)) > 0 Then
  43.     strSQL = Replace(strSQL, "1=1", "1=1 and UseInSO='[UseInSO]'")
  44.     strSQL = Replace(strSQL, "[UseInSO]", Me.UseInSO_filter)
  45. End If
  46.  
  47. If Len(Nz(Me.UseInPO_filter)) > 0 Then
  48.     strSQL = Replace(strSQL, "1=1", "1=1 and UseInPO='[UseInPO]'")
  49.     strSQL = Replace(strSQL, "[UseInPO]", Me.UseInPO_filter)
  50. End If
  51.  
  52.     Me.RecordSource = strSQL
  53.  
  54.    On Error GoTo 0
  55.    Exit Sub
  56.  
  57. FilterForm_Error:
  58.  
  59.     cswLogError Application.CurrentObjectName, "Error_ReportSelection_lb_AfterUpdate", Now, Err.Number, Err.Description
  60.     'MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure FilterForm of VBA Document Form_Inventory_MassEdit_frm"
  61.      Resume Next
  62.  
  63. End Sub
All of the text boxes that are filters have this code
Expand|Select|Wrap|Line Numbers
  1. Private Sub SKU_filter_AfterUpdate()
  2.     FilterForm
  3. End Sub
It's pretty simple. Watch out for the difference between strings and numerics. The string values you test against in the Where clause must have the quotes around them.

Jim
Aug 12 '13 #5
Rogue0801
5 New Member
Hi Jim,

Sorry for responding too late, but as I go through the codes you provided I really feel confuse. In this case, may I request you to attach a sample database for this code, that might help me understand it better.

I would really appreciate that from you.


Thanks,

Rogue
Aug 19 '13 #6
zmbd
5,501 Recognized Expert Moderator Expert
Please read thru the following articles in our "insights" section.
One of these should be a good fit for what you're after and the others should provide some points for thought for other forms you might need.
The coding is at a moderate level; however, there is a lot of reading so if you happen to get stuck, please don't hesitate to post back with any specific questions you might have. Remember, the more detail you give the better we can help!

-filtering-
Aug 19 '13 #7
Rogue0801
5 New Member
Dear zmbd,

Thanks for your intent to help, however you are really right I will get stuck to this readings and actually I have read some of this before and thru this I got inspired to apply it in my database. And I got one which suits my requirement, but the problem is I dont know how I put additional filters on it especially for date.

I would really appreciate if you could help me with this, I already got a combo wherein I can select the supplier, what I want now is to add 2 new combos wherien I could select the status and specific date range, as I mentioned in my original post.
Aug 20 '13 #8
jimatqsi
1,271 Recognized Expert Top Contributor
Here's an example I modified quickly from a working installation. Enter a value in any green box(es) to filter the screen content.

Jim
Attached Files
File Type: zip sample2.zip (269.1 KB, 63 views)
Aug 20 '13 #9
zmbd
5,501 Recognized Expert Moderator Expert
I just want to make sure that I understand what you are after:
cbox_1 = somevalue_1
cbox_2 = somevalue_2
cbox_3 = somevalue_3

You want to be able to filter the data in the form based upon one or more of the combobox values
air code:
Expand|Select|Wrap|Line Numbers
  1. (provided that none of the cbox_* are null or "")
  2. SELECT *
  3. FROM tbl_exmple
  4. WHERE ([field_1] = cbox_1
  5.    AND [field_2] = cbox_2
  6.    AND [field_3] = cbox_3
The first thing I would do is change your form.
Open up the header section of the bound form.
Place your combo boxes in the header section.
This is from a production database where I can lookup my equipment inventory (there's more to this form, I just show the top section):


You'll have to forgive the redacted areas of the picture. It has some sensitive information :).

The form is bound to my inventory table.

Now you'll note that my combo boxes are "unbound" that is because they don't directly reference anything on this form. The first has a query for the row source that pulls the human readable manufacture name (the id is the bound column) the second cascades from the first by showing only the products from the selected manufacture. If you will read thru the article on cascading comboboxes you'll get an idea as to what I've done.

The form detail is blank when loaded.
This is because the form filter is set so that no records are returned because this is a HUGE table and I don't need to return 10,000 records on open.

On first open, only the controls in the bottom, the show all button, and this first "start here" is visible.
The first CBO is set, the afterupdate forces the second CBO to requery the products table and then makes the second cbo visable. The second CBO is set, the afterupdate event then does:

Expand|Select|Wrap|Line Numbers
  1. Private Sub z_ctrl_cbo_filteronproduct_AfterUpdate()
  2. Dim zsql As String
  3. Dim zprod As Integer
  4. '
  5. zprod = Nz(Me.z_ctrl_cbo_filteronproduct.value, 0)
  6. If zprod > 0 Then
  7.     zsql = "[inventory_fk_products] = " & zprod
  8.     With Me
  9.         .Filter = zsql
  10.         .FilterOn = True
  11.         .z_ctrl_cmd_clearfilter.Visible = True
  12.     End With
  13. Else
  14.     'Clear the details, inventory will never have a 0 or lesss product FK.
  15.     zsql = "[inventory_fk_products] = 0"
  16.  
  17.     With Me
  18.         .Filter = zsql
  19.         .FilterOn = True
  20.         .z_ctrl_cbo_filtermanufacture.SetFocus
  21.         .z_ctrl_cmd_clearfilter.Visible = False
  22.         .z_ctrl_cbo_filteronproduct.Visible = False
  23.     End With
  24. End If
  25. End Sub
So, in my case, I use a cascading combobox and I wait until the user has done some choosing and then do the final filter on the bound form. This works because I have a table with manufactures and another table with products with a relationship back to manufacture. The product table is then has a relationship to an inventory table. The form is bound to the inventory table.

In your case, you may want to do something different; however, the key to this is writing that form filter.
Attached Images
File Type: jpg bytesthread_950890_cboxfilters.jpg (26.6 KB, 315 views)
Aug 20 '13 #10
Rogue0801
5 New Member
Hi zmdb & jims,

Both of your assistance are really helpful and to what I need and I am really thankful of that, but I still have one concern. Hope you still didn't fed up on me, as I really dont have that much understanding in terms of VB. To begin with I have attached my sample dbase here for your reference...I am not sure were is my mistake but error message displays "Runtime error 3131" syntax error in from clause.
Attached Files
File Type: zip db_Backup.zip (26.3 KB, 65 views)
Aug 22 '13 #11
zmbd
5,501 Recognized Expert Moderator Expert
Rogue0801
Nope, not upset with you at all - I learn as much each time I help as you do. No better way to learn than to teach IMHO.

Please go here and follow the trouble shooting steps:
> Before Posting (VBA or SQL) Code

Once you clear the compiler errors (you may have to do this several times as the compiler stops on the first error found)

Then run your code.... if you have error trapping (look for something like this
On Error Goto ErrorHandelingCode) in your code, just for now, comment it out by placing a single quote, " ' ", in front of it.

Now run your code, when you get the error message, click on the "DEBUG" button. The VBE should open and the erroring line should be highlighted. Make note of this line!
Now in the VBE press the stop button (or goto the MenuBar>Run>Reset) to stop the execution.

Remember that error line? Good ;-)
Copy and paste that line and maybe the a few lines before it... especially any line that includes a defining string used in that from statement. More than likely you have a malformed string and we need to figure out why and it will be easier to do if we have the same information....
Others may want to guess at the solution, I personally find that frustrating when on the receiving end.


As for the attachemnt.
At the risk of making you upset with me - I don't normally d/l un-requested files. Please understand that many of us cannot or will not d/l un-requested attachments. This has absolutely nothing to do with who you are... In my case, such d/l are prohibited by my ITSec staff. For many others, it is part of "safe computing/best practices" not to d/l such files.
Aug 22 '13 #12

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

Similar topics

4
3005
by: Luklrc | last post by:
Hi, I'm having to create a querysting with javascript. My problem is that javscript turns the "&" characher into "&" when it gets used as a querystring in the url EG: ...
1
1762
by: Tina McGibben | last post by:
I basically have a form with a subform with two combo boxes on the main form which filter the subform. The code below works except I cant seem to get it to show all the worksheets when there is...
2
1722
by: Sreya | last post by:
Hello..I hope someone can help me with this little that I've been having for a while. I have a form..which has many fields. one of them being a test #. what I need a combo box with only certain...
0
1267
by: Bruce Dodds | last post by:
In an Access 2003 application, the selected value in a combo box disappears after the afterupdate event of the combo box applies a filter to the form. The combo box is unbound (Control Source is...
6
13580
by: Mike Charney | last post by:
Is there a way to check a files date and time stamp from VBA in access. I have a need check a date stamp on a file that I am importing. Thanks in advance, Mike m charney at dunlap hospital...
1
1624
by: rija | last post by:
Hi folks, I need help regarding date and time comparison in PHP and MySQL My website is hosted in the USA (GMT - 8) And It is managed in Madagascar (GMT + 3) Want to consider DATE in Madagascar...
2
22638
by: drurjen | last post by:
Good morning. I am importing an XLS file into one of my tables. The fields are: Date Id Time IO 12/22/2006 2 12:48:45 PM 9 12/22/2006 16 5:40:55 AM 1 12/22/2006 16 12:03:59 PM 2 ...
4
1805
by: CrazyCruzan | last post by:
Hello, I have a table that has a string field "ANUM" that has values that always begin with 089. Then the 3 characters; 089, are followed by between 3 or 4 characters. So a typical value in...
3
5307
by: emoren777 | last post by:
how to put time and date in status bar? my code is like this : statusbar1.panels(1).text = "Status: OK" but it doesn't work... please help
1
1332
by: Duggi | last post by:
Hi All, I want to apply a date field as filter for the Dataview. How shall I do it.. How to discribe a string for DataView.RowFilter ? DataView.RowFilter = ??????????????? What would be...
0
7138
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...
1
7075
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
5662
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,...
1
5063
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...
0
4737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3222
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3212
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1572
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
781
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.