Setting table field default property in VBA

David Thorpe

New member
Local time
Today, 21:53
Joined
Apr 11, 2003
Messages
6
Can anybody advise me how to go about setting the default property of a (text) field in a table from VBA?

A database I have been using for years to run a local charity is now to be used by a group of other similar charities in the area. I have added a table that will hold details of each new charity and one of its text fields is "Charity Name".

My aim is that on using the database for the first time, each new charity will input its Name (via an appropriate Form) and that name will become the default value of a similar text field in another table.

Can this be done and, if so, how?
 
Re setting table field parameters via VBA

Had I been starting from scratch, your comments would be perfectly valid. However, a database that I have developed for my sole use (over the past 6 years) is now desired by a number of other users. I am very happy to give it to them for free, but they need to be able to change some key parameters to reflect their particular requirements. I don't want the chore of going back to square one and developing the thing all over again for multiple users!

The key parameters are (1) Scheme Name (text that appears as a heading on all screens (Forms) and reports and (2) Rate (an integer that is used as the basis for calculating various costs).

I have modified the database to include a PARAMETERS table that users will input (via a set-up form) on first use and have arranged things so that the table will never hold more than a single record. I thought it would be a simple matter to transfer this inititial information as defaults to identical fields in the main records table.

From your comments I guess two questions arise. (1) can the method I have chosen be made to work (if so, how) and (2) is there is a better way of doing it (if so, what is the method).

I'm not expecting anybody to spend oodles of time doing the work for me - but a bit of guidance to point me in the right direction would be greatly appreciated.
 
Create a new form based on your Parameters-table. Lets call it frmParams.

The form that contains the header and the integer-value fields, we'll call that one frmScheme.

In the OnLoad() property of frmScheme, use this code:

DoCmd.OpenForm "frmParams"
Me.txtHeader.Value = [Forms]![frmParams]![txtHeader].Value
Me.txtInteger.Value = [Forms]![frmParams]![txtInteger].Value
DoCmd.Close acForm, "frmParams", False

I know it's not fancy programming, but it works fine for me...

PS : If the 'header' of your form is a label-control and not a textbox, use Me.lblHeader.Caption = [Forms]...

Hope it works!

Greetz,

Seth
 

Users who are viewing this thread

Back
Top Bottom