Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

access save data

Posted on 2013-01-30
15
Medium Priority
?
376 Views
Last Modified: 2013-01-31
I have a form that saves data after leaving the last field on the form. I understand that access will automatically save the data if the form is "dirty". I don't want this to happen. I want the user to decide to save the data by pressing the "save" button on my form.

This only happens when I either 'tab' out of the field or hit enter which in essense is tabbing out.

Can I set the field control to on dirty from true to false on exit from the field. If so, what if the user wants to cancel out and return to another form by pressing another button on the form? Also do I need to set this for each field on the form? Can I set it globaly? That is, I do not want any records saved on any form until the user presses the save button on that form.

Your help would be appreciated.

Thanks
Al
0
Comment
Question by:allfredeneuman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +3
15 Comments
 
LVL 66

Expert Comment

by:Jim Horn
ID: 38836025
>I don't want this to happen. I want the user to decide to save the data by pressing the "save" button on my form.
No can do dude, unless you write a bunch of code to...
(1)  Copy your table into another 'temporary' like table.
(2)  Change your form so that the 'temporary' like table is the Record Source
(3)  Let the user edit that table as long as they want, then...
(4)  When user hits Save button write VBA code that ...
   (a)  Deletes the copied rows from original table
   (b)  Inserts the edited rows from the 'temporary' table into the original table.

Access saves records after the user navigates away from them, and afaik does not have any funcitonality that saves multiple records as a batch or transaction.

Good luck.
Jim
0
 
LVL 66

Expert Comment

by:Jim Horn
ID: 38836030
<slight change to above>
(1a)  Create a copy of your original table as another 'temporary' table.
(1b)  Make sure there are no records in it.
(1c)  When your form opens, INSERT whatever records the user is going to manipulate from the original table to the 'temporary' table.
0
 
LVL 48

Accepted Solution

by:
Dale Fye earned 668 total points
ID: 38836036
Change the Cycle property on the Other tab of the Properties dialog from "All Records" to "Current Record".

Then, instead of going to the next record after you tab out of the last field, the focus will go back to the first field of the current record.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 48

Expert Comment

by:Dale Fye
ID: 38836053
When you modify the Cycle property, it now gives you the ability to force the user to use Cancel and Close buttons to save or cancel updates to the current record.  You can use a Cancel button and the docmd.Undo method to reverse any changes to the current record, or a Save button, along with a me.Dirty statement to force Access to write the current record.
0
 
LVL 85

Assisted Solution

by:Scott McDaniel (Microsoft Access MVP - EE MVE )
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 668 total points
ID: 38836316
One method is this:

In the form's code module,, at the very top of the module (in the General Declarations section), add this:

Private fSave As Boolean

In the Form's BeforeUpdate  event, do this:

If Not fSave Then
  Cancel = True
  Msgbox 'You can't save now"
End If

Now in your Save button's click event:

Sub Yourbutton_Click()
  fSave = True
End If

Finally, in the Current event of the form, reset the value of fSave:

Sub Form_Current()
  fSave = False
End If
0
 
LVL 11

Assisted Solution

by:datAdrenaline
datAdrenaline earned 664 total points
ID: 38836367
You can indeed perform the task you seek to do (require user to press a "Save" button).  LSM provided a way, but I personally have used a method that requires less code ...

In the Form's BeforeUpdate  event, do this:

Private Form_BeforeUpdate(Cancel As Integer)
    Cancel = True
    MsgBox "You must save your changes with the Save button!"
End Sub

Open in new window

The BeforeUpdate event code above will prevent ANY Saving from occurring (except through your button with some fancy code :) ) ....

Now in your Save buttons on click code ...

Private Sub btnSaveRecord_Click()

    'Disable the BeforeUpdate event
    Me.BeforeUpdate = ""

    'Save the record
    If Me.Dirty Then Me.Dirty = False

    'Enable the BeforeUpdate event
    Me.BeforeUpdate = "[Event Procedure]"

End Sub

Open in new window



Hope this helps!
0
 

Author Comment

by:allfredeneuman
ID: 38838275
Thank you for the answers.

fyed's answer works except when I loose focus on the form - switch to another form without pressing the "save record" button. The record will still be saved.

I'm thinking either datAdrenaline or LSMconsulting might be the answer to this issue I haven't tried them yet.

maybe I can do something in the form "on lost focus"?

=Al
0
 
LVL 75
ID: 38838293
" except when I loose focus on the form - switch to another form without pressing the "save record" button. The record will still be saved."

Why?  Are you sure?
That really should not happen - since the form isn't really moving to a new record. It should remain in the current state (Dirty if an edit has occurred).

Also, I think Before Update scheme above would be problematic IF ... you need to do any kind of final validation (quite common), in which case you will need the Form BU event in tact.

Basically, you need (typically) 3 buttons on the form and the code to control them:
Save, Cancel, New Record (or Add Record).

mx
0
 
LVL 85
ID: 38838812
FWIW I've used the method I suggested in hundreds of projects, and it works every time. The only time the record is saved is if the user explicitly clicks the Save button. Otherwise, the user either (a) cannot leave the form or (b) must Undo (i.e. Esc) the changes before leaving the form.
0
 
LVL 11

Expert Comment

by:datAdrenaline
ID: 38839584
validation is not an issue with either method that i or lsm presented.  in both cases the validation can be placed in the code behind the save button.

also, in support of lsmconsulting, i too have used the technique he presented, as well as the technique i presented many many times.  both techniques are viable, i have just developed a preference for the method i proposed :)
0
 
LVL 75
ID: 38840323
Well, I wasn't really challenging either approach. Beyond that  re:

 "except when I loose focus on the form - switch to another form without pressing the "save record" button. The record will still be saved."

There is no reason 'the record will be saved' just because you happen to click on another open form. You can easily prove this to your self.  So, setting the Cycle property as fyed noted should ... take care of the 'tabbing out' issue ... UNLESS ... something else is going on.

mx
0
 
LVL 48

Expert Comment

by:Dale Fye
ID: 38840397
To be honest, I use a combination of the technique I mentioned, and the LSMs.  The only reason the technique I mentioned, by itself might not work, is if the "form" in question is actually a subform.  As soon as you move the focus off the subform, the record will be written, which is why I also use the technique that LSM suggested.
0
 
LVL 75
ID: 38840417
Correct. Based on the OP's description, I assumed no subforms.
0
 
LVL 48

Expert Comment

by:Dale Fye
ID: 38840460
as did I.
0
 

Author Closing Comment

by:allfredeneuman
ID: 38840512
Thank you for your suggestions.

I think I have what I need to know for now. I'm going to use fyed's solution and probably LSM consulting or datAdrenaline. If I cannot get it working I'll open another question.

AEN
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question