Link to home
Start Free TrialLog in
Avatar of Justin
Justin

asked on

Access 2010 Change Default Value for a Table field

Hello experts,

I have some number fields in my table that have Default Values set in the Field Properties window. These fields and the default values in them are required as a minimum for every record saved.

Every now and then, these default values will need to be changed. The users of this database are not very technically savvy. I don't want them bumbling around in design view trying to change these values. I need a text box + button press way to change the default value for these specific table fields.

Is this possible?

My database is already built, so I am trying to avoid major changes.

Thanks in advance.
Avatar of Kalpesh Chhatrala
Kalpesh Chhatrala
Flag of India image

ASKER CERTIFIED SOLUTION
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Justin
Justin

ASKER

Thanks everyone for your responses.

I shall try these methods out straight away. :)
In addition, if you want to add the textbox and button to a form that is bound to the table you want to change, you would need to set the form's RecordSource first to a null string, then restore it after changing the default value.
If this is a multi-user database, the challenge is that you have to make sure users are not using the table you are trying to modify.  Another way to deal with this is to maintain a separate table (tbl_Defaults) in your database with fields: FormName, CtrlName and DefValue.

Then, you can create a separate form for editing these values (not included in sample db).  You can place a "Defaults"  button on an Admin form or even on the particular form where you are entering the data.  When the user clicks this button, you open frm_Defaults using a WHERE condition that limits the continuous forms RecordSource to those where the [FormName] field matchs the name of your form.

Finally, in the form where the users are actually entering the data (frm1 in the example), you can use the Form_Current event to set the value of the controls on the form, rather than setting the default value of the field.  This gives you the flexibility of setting these defaults at run time and having them work for all users in a multi-user environment.

I've used the Eval() function to assess the value of the data entered in your DefValue field, since this must be a text data type.  If the Eval() function generates an error, it is because the default value is a string, and the code jumps to the error handler to process strings.

Take a look at the attached as an example.
DefValues.accdb
Avatar of Justin

ASKER

Thanks experts for your input.

I was able to use the db.TableDefs solution in my database. These default values won't be changed often, and when they are changed, it will be while no other users are using the database. This was an easy and simple fix for a beginner like me.