Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Save form after updating default values

Posted on 2013-05-31
7
Medium Priority
?
84 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
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…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

636 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