Best way to check if I need to prompt 'Do you want to save' on a number of textboxes/checkboxes? 
Author Message
 Best way to check if I need to prompt 'Do you want to save' on a number of textboxes/checkboxes?

Hi All

I know this probably sounds strange, but I wanted to run it by you in case
there is a tried and trusted method of checking what I basically call a VB6
'form' to see if any changes have been made on the form and if they have
then prompt the user to save.

I have a number of textboxes (approx 16), checkboxes (30) and dropdown menus
(16) and I only want to give the user a gentle reminder if they've changed
something.

Any suggestions would be gratefully received.

Thanks



Tue, 21 Jun 2011 04:12:42 GMT  
 Best way to check if I need to prompt 'Do you want to save' on a number of textboxes/checkboxes?


Quote:
> Hi All

> I know this probably sounds strange, but I wanted to run it by you in case
> there is a tried and trusted method of checking what I basically call a
> VB6
> 'form' to see if any changes have been made on the form and if they have
> then prompt the user to save.

> I have a number of textboxes (approx 16), checkboxes (30) and dropdown
> menus
> (16) and I only want to give the user a gentle reminder if they've changed
> something.

> Any suggestions would be gratefully received.

> Thanks

Changes can happen one of two ways, the text in the text box can be changed
to what it was before, or the selection can be changed to what is was before
the change. If you want to detect that kind of event then you would have to
put a form wide boolean varible in to the change event of that control and
set it to true, then at the sutible time check to see if the value of the
boolean varible is true.
If you just need to check if any value of a control is different to the
default or start value then at form load put the same text or value in the
controls Tag property, then loop through the controls at the appropriate
time to see if any value in the Tag property is different to the text or
value property at the needs saveing time.
Ivar


Tue, 21 Jun 2011 05:51:07 GMT  
 Best way to check if I need to prompt 'Do you want to save' on a number of textboxes/checkboxes?


Quote:
> I know this probably sounds strange, but I wanted to run it by you in case
> there is a tried and trusted method of checking what I basically call a VB6
> 'form' to see if any changes have been made on the form and if they have
> then prompt the user to save.

> I have a number of textboxes (approx 16), checkboxes (30) and dropdown menus
> (16) and I only want to give the user a gentle reminder if they've changed
> something.

> Any suggestions would be gratefully received.

There are a number of ways to do that.  Basically you record the values
of all the desired controls when the form loads (after you've programmically
filled them) and when leaving the form, you check the control values against
what you recorded earlier.

Some might suggest you fill each control's Tag property with the recorded
value. Another method that works well and is simple to implement is to
capture all the values into a large string.

EX:

Private Function ViewState() As String
Dim ctl As Long
  For ctl = 0 To Controls.Count - 1
    If TypeOf Controls(ctl) Is TextBox Then
      ViewState = ViewState & Controls(ctl).Text
    ElseIf TypeOf Controls(ctl) Is CheckBox Then
      ViewState = ViewState & CStr(Controls(ctl).Value)
    End If
  Next
End Function

In that scenareo, you'd record the state after the form loads and in
QueryUnload you'd do a simple comparison:

  If OldState <> ViewState Then
    ' Prompt to save
  End if

HTH
LFS



Tue, 21 Jun 2011 05:47:44 GMT  
 Best way to check if I need to prompt 'Do you want to save' on a number of textboxes/checkboxes?
I just use a form-scope boolean flag in the appropriate event (change event
of textboxes and the click event of checkboxes) that I check when the uses
clicks OK or cancel. You may have to set it to false after setting initial
values.

In General Declarations:
Private DirtyData as Boolean

In Form Load:

' Code to set initial values for textboxes and checkboxes
DirtyData = False

In change event of textboxes and click event of checkboxes:
DirtyData = True

When user clicks cancel:
Dim Response as Integer
Response = vbYes
If DirtyData then Response = MsgBox("There are unsaved changes. Are you sure
you want exit and discard changes?", vbYesNo, "Discard changes?")
If Response = vbYes then Unload Me

-Woodie


Quote:
> Hi All

> I know this probably sounds strange, but I wanted to run it by you in case
> there is a tried and trusted method of checking what I basically call a
> VB6
> 'form' to see if any changes have been made on the form and if they have
> then prompt the user to save.

> I have a number of textboxes (approx 16), checkboxes (30) and dropdown
> menus
> (16) and I only want to give the user a gentle reminder if they've changed
> something.

> Any suggestions would be gratefully received.

> Thanks



Tue, 21 Jun 2011 06:01:32 GMT  
 Best way to check if I need to prompt 'Do you want to save' on a number of textboxes/checkboxes?
On Thu, 01 Jan 2009 20:12:42 +0000, Laphan sez:

Quote:
> I have a number of textboxes (approx 16), checkboxes (30) and dropdown
> menus (16) and I only want to give the user a gentle reminder if they've
> changed something.

I'm just a beginner at this myself so this is probably a stupid
suggestion, but don't the controls all have an OnChange event?  If so,
you could set a flag (visible to the whole form) and then when they exit
the form check that flag.

--
Peter B. Steiger
Cheyenne, WY
If you must reply by email, you can reach me by placing
zeroes where you see stars: wypbs.**1 at gmail.com



Tue, 21 Jun 2011 09:22:40 GMT  
 Best way to check if I need to prompt 'Do you want to save' on a number of textboxes/checkboxes?
Hi Laphan,

I see there's been some good suggestions on capturing the Change event etc.
What you should also consider is visual feedback and also concurrency.
Concurrency checks are more difficult to do in situ, but a typical approach
is to draw an icon or unhide a visual indicator next to the input control,
and when the user hovers over that the concurrency info is displayed in a
tooltip. this mainly applies for the cases where the data is being written
to a shared resource such as a database and where it is possible that
another user is modifying part of the same entry or a related entry.
Visual cues for user change are simpler.  Again I like icons at the side of
the textboxes, but a lot of folk use to change the control's backcolor or
forecolor. (that has some accessibility issues though). You should also
consider utilizing the same mechanism for required fields and cross field
validation.  And also simple things such only enabling Save buttons once a
change has been made.  As the requirements get more complex, such as
concurrency, field validation, required fields, change tracking, using a
class model with properties for the data makes more sense.


Quote:
> Hi All

> I know this probably sounds strange, but I wanted to run it by you in case
> there is a tried and trusted method of checking what I basically call a
> VB6
> 'form' to see if any changes have been made on the form and if they have
> then prompt the user to save.

> I have a number of textboxes (approx 16), checkboxes (30) and dropdown
> menus
> (16) and I only want to give the user a gentle reminder if they've changed
> something.

> Any suggestions would be gratefully received.

> Thanks



Tue, 21 Jun 2011 09:50:59 GMT  
 Best way to check if I need to prompt 'Do you want to save' on a number of textboxes/checkboxes?


Quote:
> > I have a number of textboxes (approx 16), checkboxes (30) and dropdown
> > menus (16) and I only want to give the user a gentle reminder if they've
> > changed something.

> I'm just a beginner at this myself so this is probably a stupid
> suggestion, but don't the controls all have an OnChange event?  If so,
> you could set a flag (visible to the whole form) and then when they exit
> the form check that flag.

If the user changes a value, and then changes it back to what was,
is there really a need to save the data?  A simple flag will be set when
the value is changed, but not reset if they change it back....

LFS



Tue, 21 Jun 2011 11:54:45 GMT  
 Best way to check if I need to prompt 'Do you want to save' on a number of textboxes/checkboxes?

Quote:


>>> I have a number of textboxes (approx 16), checkboxes (30) and
>>> dropdown menus (16) and I only want to give the user a gentle
>>> reminder if they've changed something.

>> I'm just a beginner at this myself so this is probably a stupid
>> suggestion, but don't the controls all have an OnChange event?  If
>> so, you could set a flag (visible to the whole form) and then when
>> they exit the form check that flag.

> If the user changes a value, and then changes it back to what was,
> is there really a need to save the data?  A simple flag will be set
> when the value is changed, but not reset if they change it back....

The flip side of that is, if there's no net change, is there really
any harm in saving?

--
        Jim



Tue, 21 Jun 2011 12:53:31 GMT  
 Best way to check if I need to prompt 'Do you want to save' on a number of textboxes/checkboxes?


Quote:

> The flip side of that is, if there's no net change, is there really
> any harm in saving?

There can be as it obscures any audit trail.  Are they intentionally
confirming that data or are they signaling the are unsure so aren't touching
it ??


Tue, 21 Jun 2011 13:05:41 GMT  
 Best way to check if I need to prompt 'Do you want to save' on a number of textboxes/checkboxes?

Quote:



>> The flip side of that is, if there's no net change, is there really
>> any harm in saving?

> There can be as it obscures any audit trail.  Are they intentionally
> confirming that data or are they signaling the are unsure so aren't
> touching it ??

So you're saying the fact that they clicked an option button and then
changed their minds and clicked it back again is an indication that they are
sure of the data on the entire form? Sheesh! It doesn't even mean that they
are sure of the data they clicked! Let's face it, you're just being
deliberately argumentative.

Mike



Tue, 21 Jun 2011 17:06:58 GMT  
 Best way to check if I need to prompt 'Do you want to save' on a number of textboxes/checkboxes?
Many thanks everybody.

Much appreciated.

Rgds


Hi Laphan,

I see there's been some good suggestions on capturing the Change event etc.
What you should also consider is visual feedback and also concurrency.
Concurrency checks are more difficult to do in situ, but a typical approach
is to draw an icon or unhide a visual indicator next to the input control,
and when the user hovers over that the concurrency info is displayed in a
tooltip. this mainly applies for the cases where the data is being written
to a shared resource such as a database and where it is possible that
another user is modifying part of the same entry or a related entry.
Visual cues for user change are simpler.  Again I like icons at the side of
the textboxes, but a lot of folk use to change the control's backcolor or
forecolor. (that has some accessibility issues though). You should also
consider utilizing the same mechanism for required fields and cross field
validation.  And also simple things such only enabling Save buttons once a
change has been made.  As the requirements get more complex, such as
concurrency, field validation, required fields, change tracking, using a
class model with properties for the data makes more sense.


Quote:
> Hi All

> I know this probably sounds strange, but I wanted to run it by you in case
> there is a tried and trusted method of checking what I basically call a
> VB6
> 'form' to see if any changes have been made on the form and if they have
> then prompt the user to save.

> I have a number of textboxes (approx 16), checkboxes (30) and dropdown
> menus
> (16) and I only want to give the user a gentle reminder if they've changed
> something.

> Any suggestions would be gratefully received.

> Thanks



Tue, 21 Jun 2011 18:57:05 GMT  
 Best way to check if I need to prompt 'Do you want to save' on a number of textboxes/checkboxes?

Quote:

> "Bill McCarthy" wrote...

>> "Jim Mack" wrote ...

>>> The flip side of that is, if there's no net change, is there
>>> really any harm in saving?

>> There can be as it obscures any audit trail.  Are they
>> intentionally confirming that data or are they signaling the are
>> unsure so aren't touching it ??

> So you're saying the fact that they clicked an option button and
> then changed their minds and clicked it back again is an indication
> that they are sure of the data on the entire form? Sheesh! It
> doesn't even mean that they are sure of the data they clicked!
> Let's face it, you're just being deliberately argumentative.

I don't see McCarthy's messages, but on the bit you quoted, I'd say
it's a fair question. There might be situations where "date last
changed" must be inferred from the file date, for example.

I wasn't suggesting that there was never a reason not to save, just
posing a counter-query to Larry's question. Stated baldly: if it
doesn't matter whether you save the same data again, then the simplest
possible 'dirty' flag will do. If it does, then it gets more
complicated.

For all that, business rules may dictate that you must re-save on any
alteration, even if there is no net change. The flag becomes a
'touched' flag rather than a 'dirty' flag in that case.

--
        Jim



Tue, 21 Jun 2011 20:47:59 GMT  
 Best way to check if I need to prompt 'Do you want to save' on a number of textboxes/checkboxes?


Quote:
> I'm just a beginner at this myself so this is probably a stupid
> suggestion, but don't the controls all have an OnChange event?

No. VB controls do not have any OnANYTHING events, because VB thankfully
doesn't use that stupid Javascript naming. Change, Click, KeyPress. Simple
and to the point without a redundant word at the beginning.


Tue, 21 Jun 2011 22:24:52 GMT  
 Best way to check if I need to prompt 'Do you want to save' on a number of textboxes/checkboxes?


Quote:
> > If the user changes a value, and then changes it back to what was,
> > is there really a need to save the data?  A simple flag will be set
> > when the value is changed, but not reset if they change it back....

> The flip side of that is, if there's no net change, is there really
> any harm in saving?

None that I can see, the harm is popping up a message box
every time the user wants to leave the form.  So it boils down to
a little bit o' logic.  Do you just go ahead and save the data?  That's
not a good idea because the user might make a change, but not want
to save it.  So, do you go ahead and ask every time?  Another bad
idea, imagine you open notepad and then close it right away without
doing anything.  Popping up a save query would sure appear dumb.

The best approach is to check to see if data has changed, and only pop
up the box if there was a change.  Its the smart/intuitive thing to do.

LFS



Tue, 21 Jun 2011 23:57:53 GMT  
 Best way to check if I need to prompt 'Do you want to save' on a number of textboxes/checkboxes?


Quote:


> > > If the user changes a value, and then changes it back to what was,
> > > is there really a need to save the data?  A simple flag will be set
> > > when the value is changed, but not reset if they change it back....

> > The flip side of that is, if there's no net change, is there really
> > any harm in saving?

> None that I can see,

But there might be, depending on the OP's business rules.  Only he can
answer that with any assurance.  He's probably got enough suggestions go
generate something that will work for him.

....

--
/~\ The ASCII
\ / Ribbon Campaign
 X  Against HTML
/ \ Email!

Remove the ns_ from if replying by e-mail (but keep posts in the
newsgroups if possible).



Wed, 22 Jun 2011 01:07:49 GMT  
 
 [ 18 post ]  Go to page: [1] [2]

 Relevant Pages 

1. exiting word without 'save' prompt

2. Save XL file but don't want XL to prompt user

3. I need to obtain a bios's or mother's serial number in VB

4. 'Activedocument.saved = false' after save

5. Best way to save user's project

6. Can't check the text and number

7. Can't check the text and number

8. ADO thinks DBMS is done, but DBMS ain't done

9. Cookie with a negative number in it doesn't save

10. Sources Wanted ---- 'Mime'

11. 'Money wanted' algorithm (Cobol version)

12. Wanted: Icon for 'unattended' DLL

 

 
Powered by phpBB® Forum Software