Results 1 to 9 of 9

Thread: Urgent help needed to "Filter" the data...

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2005
    Posts
    69

    Urgent help needed to "Filter" the data...

    Hi,

    Can somebody modify this code so that I can filter the data by "Customer Name" "Sales Person" & "City".

    The following is the code:
    Note: Here in this code "fname" & "lname" or the names of Option Buttons. And Text9 is the Text Box where user can enter the text to filter.
    VB Code:
    1. Private Sub Text9_Change()
    2. rs.Close
    3. If fname.Value = True Then
    4.     rs.Open "Select * from dept where fname like '" & Text9 & "%'", db
    5.     rs.Requery
    6. Else
    7.     rs.Open "Select * from dept where lname like '" & Text9 & "%'", db
    8.     rs.Requery
    9. End If
    10.  
    11. If rs.RecordCount <> 0 Then
    12.     show_rec
    13. Else
    14.     clear_txt
    15. End If
    16. End Sub

    Thanks in advance for any help.

    sweetie_2005





    Edit: Added [vbcode][/vbcode] tags and indenting for clarity. - Hack
    Last edited by Hack; Oct 11th, 2005 at 06:04 AM.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Urgent help needed to "Filter" the data...

    First, fname and lname should not be the names of option buttons. The buttons should be called something like optfname and optlname.

    Second, are you saying that in addition to being option button names, fname and lname are also fields in your database? Thats confusing.

    You want to query on Customer Name, Sales Person and City. What db fields holds this information? Do you want individual queries on each of the three, or one query based on all three?

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2005
    Posts
    69

    Re: Urgent help needed to "Filter" the data...

    Quote Originally Posted by Hack
    First, fname and lname should not be the names of option buttons. The buttons should be called something like optfname and optlname.

    Second, are you saying that in addition to being option button names, fname and lname are also fields in your database? Thats confusing.

    You want to query on Customer Name, Sales Person and City. What db fields holds this information? Do you want individual queries on each of the three, or one query based on all three?
    ------------------------------------------------------------------------

    "fname" & "lname" or table fields names
    and fname=first name, lname=last name
    now i can filter data using fname or lname depends upon chosing the option button.

    Now I dont need to filter data using "fname" or "lname" instead of that I would like to filter data using "customer name" "sales person" & "city" these are the names given in table and the same names assigned to option buttons.

    plz help.

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Urgent help needed to "Filter" the data...

    Quote Originally Posted by sweetie_2005
    ------------------------------------------------------------------------

    "fname" & "lname" or table fields names
    and fname=first name, lname=last name
    now i can filter data using fname or lname depends upon chosing the option button.

    Now I dont need to filter data using "fname" or "lname" instead of that I would like to filter data using "customer name" "sales person" & "city" these are the names given in table and the same names assigned to option buttons.

    plz help.
    How is customer name stored? In what field is it stored?

    How is sales person name stored? In what field is it stored?

    Same with city?

    How do I select a customer name?
    How do I select a sales person name?
    How do I select a city?

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Sep 2005
    Posts
    69

    Re: Urgent help needed to "Filter" the data...

    VB Code:
    1. Private Sub Text9_Change()
    2. rs.Close
    3. If fname.Value = True Then
    4.     rs.Open "Select * from dept where fname like '" & Text9 & "%'", db
    5.     rs.Requery
    6. Else
    7.     rs.Open "Select * from dept where lname like '" & Text9 & "%'", db
    8.     rs.Requery
    9. End If
    10.  
    11. If rs.RecordCount <> 0 Then
    12.     show_rec
    13. Else
    14.     clear_txt
    15. End If
    16. End Sub
    Friend, just let me know here in the above code is "IF" & "ELSE " because only two options are there suppose if i have four options in which i can select anyone OPTION how the could would be.
    VB Code:
    1. Private Sub Text9_Change()
    2. rs.Close
    3. If fname.Value = True Then
    4.     rs.Open "Select * from dept where fname like '" & Text9 & "%'", db
    5.     rs.Requery
    6.  
    7. [B]'ACTUALLY I NEED THE CODE HERE TO CHOOSE ANOTHER TWO OPTION'[/B]
    8.  
    9. Else
    10.     rs.Open "Select * from dept where lname like '" & Text9 & "%'", db
    11.     rs.Requery
    12. End If
    Last edited by Hack; Oct 11th, 2005 at 06:52 AM.

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Urgent help needed to "Filter" the data...

    Please use [vbcode][/vbcode] tags when posting code. It makes it so much easier to read.
    Quote Originally Posted by sweetie_2005
    Friend, just let me know here in the above code is "IF" & "ELSE " because only two options are there suppose if i have four options in which i can select anyone OPTION how the could would be.
    Then, put four option buttons on your form.

    Also, why are you running your query from the change event of a textbox???

    At the very least, you should be running your query from the click event of one of your option buttons. If you do that, you don't need an If/Else.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Sep 2005
    Posts
    69

    Re: Urgent help needed to "Filter" the data...

    Dear Friend, Could you tell me the following code is correct which i added in between with bold letters. The code is ok. but i need more options so that i need to add more options:

    Private Sub Text9_Change()
    rs.Close
    If fname.Value = True Then
    rs.Open "Select * from dept where fname like '" & Text9 & "%'", db
    rs.Requery

    If Cutomer.Value = True Then
    rs.Open "Select * from dept where customer like '" & Text9 & "%'", db
    rs.Requery


    If city.Value = True Then
    rs.Open "Select * from dept where city like '" & Text9 & "%'", db
    rs.Requery


    Else
    rs.Open "Select * from dept where lname like '" & Text9 & "%'", db
    rs.Requery
    End If

    If rs.RecordCount <> 0 Then
    show_rec
    Else
    clear_txt
    End If
    End Sub
    Last edited by sweetie_2005; Oct 11th, 2005 at 07:41 AM.

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Urgent help needed to "Filter" the data...

    You didn't answer my question.

    Why are you doing this from the change event of your textbox?

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Sep 2005
    Posts
    69

    Re: Urgent help needed to "Filter" the data...

    Quote Originally Posted by Hack
    You didn't answer my question.

    Why are you doing this from the change event of your textbox?
    ----------------------------------------------------------------------

    Actually i want to modify the following project (and create new database) according to my requirements.

    That's why i need it.

    Regards,

    sweetie_2005
    Attached Files Attached Files

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