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
    171

    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
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

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

    Re: detect if a combobox text has changed

    *removed
    Last edited by chris-2k; Nov 9th, 2013 at 04: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
  •  



Click Here to Expand Forum to Full Width