|
-
Jan 27th, 2011, 04:19 PM
#1
Thread Starter
New Member
Hola! Rowfilter with multiples criterias
Good Evening!!!
I'm Álvaro, a 23yo Spaniard who is trying to write a small program to control the stock of tools and spare parts for a heritage railway association.
I have created an Acces database with the 2007 version, and I'm using VB2008 to do a small application to control the inventory. I've managed to do almost everything I want for the moment except one thing.
I want to do a search tool of the database with two criterias:
1-Name of the spare piece ("Article")
2-Number of units of the Spare piece ("Quantity")
I have created a RowFilter to do the search, the code is as follows:
Dim view As New DataView
view.Table = PruebasDataSet.Almacén
view.RowFilter = "Article LIKE'" & TextBox1.Text & "%'"
AlmacénDataGridView.DataSource = view
AlmacénDataGridView.Update()
This means that the search uses the name of the spare part in the "Article" column and compares it to the Text in the TextBox
What I would like to do is, using a Checkbox, adding another criteria to the RowFilter.
When the checkbox is checked it would include in the search the following criteria: Quantity >0, meaning there are units available of the Article.
When the Checkbox is unchecked, it would include available and non available articles.
Thank you very much in advance.
Saludos
Álvaro
-
Jan 27th, 2011, 06:49 PM
#2
Re: Hola! Rowfilter with multiples criterias
Welcome to VBForums 
I probably haven't got the syntax for the checkbox quite right, but this should give you the idea:
Code:
If CheckBox1.Checked = False Then
view.RowFilter = "Article LIKE'" & TextBox1.Text & "%'"
Else
view.RowFilter = "Article LIKE'" & TextBox1.Text & "%' AND Quantity > 0"
End If
Alternatively use a String variable to build the filter, eg:
Code:
Dim MyRowFilter as String = ""
MyRowFilter = "Article LIKE'" & TextBox1.Text & "%'"
If CheckBox1.Checked = True Then
MyRowFilter &= " AND Quantity > 0"
End If
view.RowFilter = MyRowFilter
This takes more lines, but is a bit easier to read - and if you add more conditions later it will be much simpler than the previous method.
-
Jan 28th, 2011, 05:51 AM
#3
Thread Starter
New Member
Re: Hola! Rowfilter with multiples criterias
Thank you very much for your useful reply!!!
Álvaro
-
Jan 28th, 2011, 03:44 PM
#4
Thread Starter
New Member
Re: Hola! Rowfilter with multiples criterias
I'm sorry but another problem ocurred for the search engine
I have a column in my access database called "Trains" where I include the trains in which the spare parts can be used. Some spare parts can be used by more than one trains, so the field "Trains" could look like that "440-096; 435-005" and other fields may only include one type of train "435-005". However If in the textbox I write "435-005" the search would only return the registry in which Trains includes only "435-005", and not the other one.
I would like to thank in advance all the replies.
Saludos
Álvaro
-
Jan 29th, 2011, 03:50 AM
#5
Re: Hola! Rowfilter with multiples criterias
When you want a partial match like that, use Like (rather than = ) as you did above.
Assuming you want to find the value anywhere in the field, put wildcards before and after the value (rather than just after as you did above).
-
Jan 31st, 2011, 06:40 PM
#6
Thread Starter
New Member
Re: Hola! Rowfilter with multiples criterias
Thank you again for your help!!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|