pullling values from a Default Data Table during data entry

  • Thread starter Thread starter nChicago
  • Start date Start date
N

nChicago

Hi!
I am storing various default values in a default data table. [let's call it
table D]

When adding a new record to another table [table A], I'd like to query table
D and set the values for fields in the table A form. Conceptually and
technically, how would I do this?

I haven't started using VBA yet, so I'm hoping there's a way to do this
without going to VBA.

Thanks.

N
 
Hi!
I am storing various default values in a default data table. [let's call it
table D]

When adding a new record to another table [table A], I'd like to query table
D and set the values for fields in the table A form. Conceptually and
technically, how would I do this?

I haven't started using VBA yet, so I'm hoping there's a way to do this
without going to VBA.

Lynn's question is apropos - why??

In any case you cannot do this without some (relatively easy) VBA. One
way to do it would be to set the DefaultValue property of each
appropriate form control in the Form's Open event:

Private Sub Form_Open(Cancel as Integer)
Me!txtThis.DefaultValue = Chr(34) & DLookUp("[This]", "[D]") & Chr(34)

<etc>

If the field named This in table D contains Brooklyn then this code
will set the default value property of the textbox named txtThis on
your form to

"Brooklyn"

with the quotes. Since the DefaultValue property is a Text value, the
quotes are essential, even for date or numeric fields.

John W. Vinson[MVP]
 
Lynn,

The reason I want to use a default value stored in default table is as
follows:

I want each user to be able to choose their own default value. The defualt
record form has a combo box that lists various domain values for each field.
The user then selects one and it's PK is stored in the default record; e.g.
each user can choose their own default currency.

Thanks and looking forward to your reply.

Regards,

N


Lynn Trapp said:
I am storing various default values in a default data table. [let's call
it table D]

Why do you need to do that, when you can simply add a default value to
each of the table fields in the table's design view?



--
Lynn Trapp
MS Access MVP
www.ltcomputerdesigns.com
Access Security: www.ltcomputerdesigns.com/Security.htm
Jeff Conrad's Big List: www.ltcomputerdesigns.com/JCReferences.html
 
John,

thank you. Looks like I'll have to try VBA (hmmm...what trouble will I get
into?).

How do I make sure the default value is ONLY set when adding a record,
versus loading one in?

Thanks.

N


John Vinson said:
Hi!
I am storing various default values in a default data table. [let's call
it
table D]

When adding a new record to another table [table A], I'd like to query
table
D and set the values for fields in the table A form. Conceptually and
technically, how would I do this?

I haven't started using VBA yet, so I'm hoping there's a way to do this
without going to VBA.

Lynn's question is apropos - why??

In any case you cannot do this without some (relatively easy) VBA. One
way to do it would be to set the DefaultValue property of each
appropriate form control in the Form's Open event:

Private Sub Form_Open(Cancel as Integer)
Me!txtThis.DefaultValue = Chr(34) & DLookUp("[This]", "[D]") & Chr(34)

<etc>

If the field named This in table D contains Brooklyn then this code
will set the default value property of the textbox named txtThis on
your form to

"Brooklyn"

with the quotes. Since the DefaultValue property is a Text value, the
quotes are essential, even for date or numeric fields.

John W. Vinson[MVP]
 
How do I make sure the default value is ONLY set when adding a record,
versus loading one in?

If you put the code as suggested, it will set the DefaultValue
property of the Form (not of the table); only data entered by typing
(or copying an pasting) data into the Form will be affected.

John W. Vinson[MVP]
 
Back
Top