Solved

Save form after updating default values

Posted on 2013-05-31
7
56 Views
Last Modified: 2016-07-05
I'm trying to have a form save automatically after updating values.

I have two fields that I've successfully been able to get to update the default values with the last values entered, but when the form is closed and reopened without physically saving, it reverts to the old default values.

My form has two fields and a button that runs a macro.

This is the code to update the default values of the two fields:

Option Compare Database

Private Sub Mailer_LostFocus()

    Me.Mailer.DefaultValue = Chr(34) & Me.Mailer.Value & Chr(34)

End Sub

Private Sub Start_LostFocus()

    Me.Start.DefaultValue = Chr(35) & Me.Start.Value & Chr(35)

End Sub

Open in new window


Then in the Macro that I'm running, at the end I use the "SaveObject" command and pick Object type "Form" and Object Name "Run Me".

Somehow though, the form is not actually saving when the command runs.  Is there a VBA command I can run after each of the two above to cause the form to save?

Thanks for your help!
0
Comment
Question by:dgran
  • 3
7 Comments
 
LVL 84
ID: 39211778
You can use this to force Access to save your data:

If Me.Dirty Then Me.Dirty = False

But I'm not sure what you mean by "it reverts to the old default values.". Default values are values that Access fills in for NEW records. They have no bearing on existing data.
0
 

Author Comment

by:dgran
ID: 39211851
The VBA code I use (above) updates the default value of the field to the new value entered.  When I enter a new value, save and close the form and then reopen it, the old value still appears.  After entering the new value, I've opened properties and checked the default value and it is correctly updating to the new value, but somehow, when I close and reopen the form without manually saving THAT FORM, it reverts to old default values instead of the new ones assigned by the VBA code (above).
0
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 250 total points
ID: 39211927
I see - you're trying to persist the Default Value of a Form's CONTROL? If so, the only way to do that is by opening the form in Design view (and there are a multitude or reasons you shouldn't do that in a production database).

Instead, you could use the Current event of the Form to set your default values:

Sub Form_Current()

If Me.NewRecord Then
  Me.SomeField1 = DefaultValue1
  Me.SomeField2 = DefaultValue2
End If

You could then store your DefaultValues in a table, which can be persisted between "sessions".
0
 
LVL 21

Assisted Solution

by:Boyd (HiTechCoach) Trimmell, Microsoft Access MVP
Boyd (HiTechCoach) Trimmell, Microsoft Access MVP earned 250 total points
ID: 39217969
Since I compile all my front ends into a MDE/ACCDE I can't save a form's design changes.

What I do is use the Form's On Load event to load the default value for the form

A simple way for a single user apps is to read the last record in the table to set the default values in the form's On Load event

If it is a multiple user app and each user wants their own defaults then I use separate table to store the default values. You will also have to save the defaults using the Form's After Update or  On Unload event.  The table has the fields: User Name, Form Name, Control Name, and default value.  This allows a single table to hold all default values for an application
0
 
LVL 84
ID: 41691823
The two comments below provide instructions on persisting a Form's Default Value between sessions, and should be accepted as the solutions:

https://www.experts-exchange.com/questions/28144383/Save-form-after-updating-default-values.html#a39211927
https://www.experts-exchange.com/questions/28144383/Save-form-after-updating-default-values.html#a39217969
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

860 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