Results 1 to 5 of 5

Thread: silly problem with rs updating unnecessarily

  1. #1

    Thread Starter
    Addicted Member BIOSTALL's Avatar
    Join Date
    Apr 2005
    Location
    Northampton, UK
    Posts
    180

    silly problem with rs updating unnecessarily

    hey, i have studied this for hours and yet, i cannot solve the problem. What i have is 6 comboboxes. Now, if any of these comboboxes text values is equal to 'Any', i change the text value in then combobox to '%'. This way i can do a sql query such as:

    rs.source = "select * from Cars where Car_Colour like '" & combo1.text & "'"

    Now this works fine, but i then have to change the comboboxes value back to 'Any'. This then results in the rs being empty and therefore i cant movenext, moveprevious or anything else. Closing the rs before changing them back to 'Any' also clears the rs.

    Has anyone got a way to keep the rs as it is when i do the query, yet still b able to change the comboboxes text back to 'Any'. Any help would be GREATLY appreciated as i'm tearing my hair out over this thanks

    BIOSTALL

  2. #2
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: silly problem with rs updating unnecessarily

    Sounds like you are using bound controls - which I am not familiar with...

    But you should be able to do:

    VB Code:
    1. rs.source = "select * from Cars where Car_Colour like '" & IIF(combo1.text="ANY","%",combo1.text) & "'"

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  3. #3

    Thread Starter
    Addicted Member BIOSTALL's Avatar
    Join Date
    Apr 2005
    Location
    Northampton, UK
    Posts
    180

    Re: silly problem with rs updating unnecessarily

    Nope, its still doing the same thing What i've done is attached my project. The form i am having trouble with is frmSelectCar in the cmdSearch_Click() sub. I've added a temporary datagrid onto the form just to show what the rs contains.

    Note how the only time it fails (rs is cleared) is when cmbMake is equal to 'Any'. If cmbMake is not equal to 'Any' then the rs will remain populated and i can then move through the records. If it is equal to 'Any' then whatever is in rs is emptied I just cant figure it out so if someone wouldnt mind looking through my code, i would be very grateful Thanks, BIOSTALL

    PS. If you would like to know anything else (eg. anything you dont understand about my project), just ask

  4. #4
    Lively Member
    Join Date
    Apr 2005
    Posts
    91

    Re: silly problem with rs updating unnecessarily

    Hi,

    In your cmdsearch_click() event you have

    If cmbMake.Text = "Any" Then
    cmbMake.AddItem "%", 0
    cmbMake.RemoveItem (1)
    cmbMake.ListIndex = 0
    'When the code gets to here it jumps to Private Sub cmbMake_Click()
    End If
    This is where the problem is. Why it's doing it I don't know.
    It's not on the first calling but on the second where you are asking for "%" it changes the cmdModel
    so when it comes back it's allready "Any"

    Hope this helps will try more later

    Fishy

  5. #5

    Thread Starter
    Addicted Member BIOSTALL's Avatar
    Join Date
    Apr 2005
    Location
    Northampton, UK
    Posts
    180

    Re: silly problem with rs updating unnecessarily

    Right, when i was changing the values from '%' back to 'Any', what i've done is put this in the cmdSearch_LostFocus() and it works fine Thanks for your help Fishy.

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