Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Do you want to save your changes? Q. 1

Status
Not open for further replies.

Andrzejek

Programmer
Jan 10, 2006
8,569
US

Here is the situation:
VB 6 app, ORACLE database, and I have an update Form. On the Form I have combo boxes, text boxes, option buttons, tab, grid, etc.

User wants to be notified when he/she makes any changes and wants to move to another record / move away from the Form - with a note “Do you want to save your changes?” if he/she did not hit the Update button.

Sounds simple, have a switch in all change events for text boxes, click of combo boxes, etc. but those events fire when I populate them from my database as well. And I don’t want to have another blnSkip As Boolean for every event just to set it when data is coming from DB and re-set it when I am ready for user input.

How do you do it in your application?


Have fun.

---- Andy
 
Set your switches in the "Mouse_down" event, as opposed to the "click" event, where applicable. I've had bad luck relying on the textbox's "change" event, so I've loaded the values in the textboxes into strings and made comparisons to determine when a change has been made.

HTH

Chew

10% of your life is what happens to you. 90% of your life is how you deal with it.
 
...although my "solution" is only good if the user uses the mouse to make changes. Some changes can be made using the keyboard. If you want to capture keystrokes too, then I don't see anyway around loading each control's value into a variable and comparing the values when the user exits the form w/o clicking the "Update" button.

Chew


10% of your life is what happens to you. 90% of your life is how you deal with it.
 
Well, the change event of each control just needs to call a single procedure that sets a dirty flag. So something like the following on a form:

Private FormDirty as Boolean
Private Loading as Boolean

Private Sub SetFormDirty()
If Not Loading Then FormDirty=True
End Sub

Private Sub Command1_Change()
SetFormDirty
End Sub

Private Sub Form_Load()
Loading=True
LoadFromDB
Loading=False
End Sub

 

So far I have something close to strongm's way:

I have 2 variables:
Code:
Dim blnDataIsLoading As Boolean
Dim blnFormIsUpdated As Boolean
and turn blnDataIsLoading ON when loading data and OFF when done, and in some events check the blnDataIsLoading and set the blnFormIsUpdated ON, in cmdUpdate back to OFF

With a little of playing with it I think I have it working OK.

ChewDoggie, I was planning to use Mouse_Click or Key_Press events, but that's too much hassle.


Have fun.

---- Andy
 
You could be a bit more precise too
Code:
Private FormDirty as Boolean
private FormItemDirty(0 to 4) ' say you have 5 fields

Private Sub SetFormDirty(DirtyItem as integer)
    If Not Loading Then
          FormDirty=True
          FormItemDirty(DirtyItem) =true
    end if
End Sub

and during your save routine you can parse through the FieldDirty array and find which field(s) were changed

Obviously, this relies in the rest of the code as sketched by strongm

You woudl need to be scrupulous about your Item numbers - I usually use a list constants.



Take Care

Matt
I have always wished that my computer would be as easy to use as my telephone.
My wish has come true. I no longer know how to use my telephone.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top