Results 1 to 6 of 6

Thread: Hola! Rowfilter with multiples criterias

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2011
    Posts
    7

    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

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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.

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2011
    Posts
    7

    Re: Hola! Rowfilter with multiples criterias

    Thank you very much for your useful reply!!!

    Álvaro

  4. #4

    Thread Starter
    New Member
    Join Date
    Jan 2011
    Posts
    7

    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

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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).

  6. #6

    Thread Starter
    New Member
    Join Date
    Jan 2011
    Posts
    7

    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
  •  



Click Here to Expand Forum to Full Width