Results 1 to 11 of 11

Thread: Save button on a form

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2005
    Location
    NTU, Singapore
    Posts
    42

    Question Save button on a form

    Hi,

    I have a weird problem. In one of my forms which allows users to edit the record on my database, I have a save button. When the user has edited the form and clicks on the save button, the record is saved. I also have to maintain a log of who is accessing my database and doing what, so I have a separate function called log_save() which I call everytime the user clicks on the save button. But the problem is that if the user clicks multiple times on the save button, I get multiple entries on my Logtable. Is there a way to identify if a user has made any further changes after he has clicked the save button once? (Just like it is in microsoft word or whereever, when the user has clicked on the save button once and if he doesn't make any more changes then he can simply exit without being prompted to save changes again) I tried using form's Me.dirty event but apparently it doesnot serve the purpose.

    Thanks

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Save button on a form

    Sure thas an easy one. If you create a boolean variable at the form level you can set it to false after the forms loads. Then in each control change event you can set your boolean flag to True. When you click on the save button you change it back to false. If the variable is false when save is clicked you dont write out to your log file.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2005
    Location
    NTU, Singapore
    Posts
    42

    Re: Save button on a form

    thanks rob. Can I ask you another question?

    Is there a way for me to manually set to false the form dirty property? Thanks

    I made sure to rate your earlier post.

  4. #4
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: Save button on a form

    rochak,

    you can just do

    VB Code:
    1. Me.Dirty = False
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  5. #5

    Thread Starter
    Member
    Join Date
    Aug 2005
    Location
    NTU, Singapore
    Posts
    42

    Re: Save button on a form

    danny, this does not seem to work. Once I have done me.dirty = false, on subsequent edits or changes to the form the dirty property is not automatically set to true again
    When you know you can do it, there is no power on earth that can stop you.

  6. #6
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: Save button on a form

    The property will switch back to true as soon as a bound field control is changed..

    For example when a form initially loads it's dirty property is False

    As soon as a textbox has it's entry changed if you peform a msgbox stating simply

    VB Code:
    1. MsgBox Me.Dirty

    Then it should say True.. if it doesn't then your control is not bound.
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  7. #7

    Thread Starter
    Member
    Join Date
    Aug 2005
    Location
    NTU, Singapore
    Posts
    42

    Re: Save button on a form

    yes you are right. My control is unbound. Any way to get it done in this.
    When you know you can do it, there is no power on earth that can stop you.

  8. #8
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: Save button on a form

    What you will have to do is capture the control's original value before any changes are made.. then after it has been made check to ensure that it is different and then set the dirty property to true.
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  9. #9

    Thread Starter
    Member
    Join Date
    Aug 2005
    Location
    NTU, Singapore
    Posts
    42

    Re: Save button on a form

    does this mean, that I will have to do it for each and every control? Because in that case, using me.dirty is not the only soln. I might as well use any flag variable for the purpose.
    When you know you can do it, there is no power on earth that can stop you.

  10. #10
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: Save button on a form

    That is one of the things bound forms are good for..

    Yes you will have to validate each control before sending it to the table..

    If you do not want users directly changing the table's data then pull to a temporary table and bind the form to this.. therefore allowing an experienced user the option to review the changes and then submit them back to the main table..
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  11. #11

    Thread Starter
    Member
    Join Date
    Aug 2005
    Location
    NTU, Singapore
    Posts
    42

    Re: Save button on a form

    yup thanks, it works.
    When you know you can do it, there is no power on earth that can stop you.

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