?
Solved

Save form after updating default values

Posted on 2013-05-31
7
Medium Priority
?
75 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
[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
  • 3
7 Comments
 
LVL 85
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 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 1000 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 1000 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 85
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Suggested Courses

777 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