detect if a combobox text has changed-VBForums
Results 1 to 4 of 4

Thread: detect if a combobox text has changed

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2003
    Location
    Stourbridge, England, UK
    Posts
    147

    detect if a combobox text has changed

    Hello,

    On a form I have a combobox that displays either YES or NO.
    I also have a SAVE command button that saves any changes to a database, If the PAGE CLOSE command button is clicked, I need to detect if the YES NO text has changed and if it has been changed and the SAVE button has not been clicked, I need to display a message prompting the user to save.

    I dont know how to detect if the combobox has changed when the user clicks the CLOSE button.

  2. #2
    VBaholic & Loving It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    GetWindowRect()
    Posts
    11,999

    Re: detect if a combobox text has changed

    I believe I understand the problem, but here's another scenario....
    User has Combo = YES, and then clicks the save button, and then does more database changes. In what you are describing, you wouldn't catch this when Page Close occurs, or are there other checks you haven't described?

    Assuming the above scenario can't happen, then an easy answer might be as follows. Another assumption: combo1 style is 2 (dropdown list)
    1. At top of from add: Dim bDirty as Boolean
    2. In your Save button click event: bDirty=False
    3. In your combobox click event:
    If Combo1.Text = "YES" Then bDirty=True Else bDirty=False
    4. In your PageClose event:
    If bDirty = True Then ' prompt for saving

    Now if you have any other code that checks whether something changed that should be saved, then in that event/routine:
    If Combo1.Text = "YES" Then bDirty=True

    Tip: In any text boxes that contain field data, in the Change event, you can set bDirty=True to indicate something changed; your decision.

  3. #3
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: detect if a combobox text has changed

    Quote Originally Posted by LaVolpe
    Tip: In any text boxes that contain field data, in the Change event, you can set bDirty=True to indicate something changed; your decision.
    This is referred to as a "dirty flag" and a method I've been employing for years.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  4. #4
    Hyperactive Member
    Join Date
    Mar 2013
    Posts
    319

    Re: detect if a combobox text has changed

    *removed
    Last edited by chris-2k; Nov 9th, 2013 at 03:00 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.