Default date in a table field

M

Manolo Hernandez

I have been unsuccessfully looking for an expression I can
use in a date field as a default value, the value I want
has to get a date from another table and add 60 days to
it, I have tried all I can find in the book and even the
one I used in school but can not get it to work, I know
there must be a simple way to do this, could you please
help me?
Thanks.
 
D

Duane Hookom

You can't reference another table or field in the Default Value property of
a field. You can do this in a form where all of your data entry should be
handled.
 
T

Tim Ferguson

I have been unsuccessfully looking for an expression I can
use in a date field as a default value, the value I want
has to get a date from another table and add 60 days to
it,

In general, you are very limited in what you can achieve in a DefaultValue
property. I don't know what value you are looking for in another table, but
it's possible that DLookUp would work:

.DefaultValue = _
"DLookUp(""SomeDateField"", ""MyOtherTable"", ""MyOtherKey=57"")"

but I wouldn't guarantee it. You can certainly do this on a form as part of
the OnCurrent or BeforeInsert events.

Hope that helps


Tim F
 
J

John Vinson

I have been unsuccessfully looking for an expression I can
use in a date field as a default value, the value I want
has to get a date from another table and add 60 days to
it, I have tried all I can find in the book and even the
one I used in school but can not get it to work, I know
there must be a simple way to do this, could you please
help me?

A table Default property is not allowed to reference any table field,
in the current table or any other table. The only way to do this is to
use a Form to enter the data, and use VBA code in the Form's
BeforeInsert event to set the default:

Private Sub Form_BeforeInsert(Cancel as Integer)
Me!txtDatefield = DateAdd("d", 60, DLookUp("[datefield]", "[other
table name]", <optional criteria to select which record>)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top