how to add day in the next record

S

Sumeth

Hi,
I have a date field in a form. But I need the default value of that field is
add one day in the next new record.

How can I do that.

like : the last record date value is "31/1/2009" but the default value in
the next new record might be "1/2/2009".

thanks,
 
K

ken

Provided the form isn't being closed then you can set the DefaultValue
property of the relevant control in the form's AfterInsert event
procedure:

Me.[YourDate].DefaultValue = """" & DateAdd("d",1,Me[YourDate]) & """"

Note that the DefaultValue property is always a string expression
regardless of the underlying field's data type, which is why the value
assigned to it wrapped in literal quotes in the above code.
Otherwise it will be treated as an arithmetical expression and give
the wrong result.

If you always want the default date to be the date following the
latest date in the underlying table opens then you could out the
following in the form's Current event procedure, e.g.

Dim dtmDefaultDate as Date

dtmDefaultDate = DateAdd("d", 1, DMax([YourDate], [YourTable]))

Me.[YourDate].DefaultValue = """" & dtmDefaultDate & """"

Note, however, that in a multi-user environment on a network, two or
more users inserting records simultaneously would get the same date as
the default, leading to a conflict. To avoid that you'd need to index
the date field uniquely and handle the conflict using a method similar
to that for handling conflicts in Roger Carlson's demo file for custom
'autonumbering' at:

http://www.rogersaccesslibrary.com/...?TID=395&SID=83z7c11zc7b721d2a1e51989c53d7ffb

or my more complex one, which also allows for the next value to be
reset, at:

http://community.netscape.com/n/pfx...yMessages&tsn=1&tid=23839&webtag=ws-msdevapps

Ken Sheridan
Stafford, England
 
S

Sumeth

Thanks Ken,

It can solve that problem now. And work well. Thanks.


Provided the form isn't being closed then you can set the DefaultValue
property of the relevant control in the form's AfterInsert event
procedure:

Me.[YourDate].DefaultValue = """" & DateAdd("d",1,Me[YourDate]) & """"

Note that the DefaultValue property is always a string expression
regardless of the underlying field's data type, which is why the value
assigned to it wrapped in literal quotes in the above code.
Otherwise it will be treated as an arithmetical expression and give
the wrong result.

If you always want the default date to be the date following the
latest date in the underlying table opens then you could out the
following in the form's Current event procedure, e.g.

Dim dtmDefaultDate as Date

dtmDefaultDate = DateAdd("d", 1, DMax([YourDate], [YourTable]))

Me.[YourDate].DefaultValue = """" & dtmDefaultDate & """"

Note, however, that in a multi-user environment on a network, two or
more users inserting records simultaneously would get the same date as
the default, leading to a conflict. To avoid that you'd need to index
the date field uniquely and handle the conflict using a method similar
to that for handling conflicts in Roger Carlson's demo file for custom
'autonumbering' at:

http://www.rogersaccesslibrary.com/...?TID=395&SID=83z7c11zc7b721d2a1e51989c53d7ffb

or my more complex one, which also allows for the next value to be
reset, at:

http://community.netscape.com/n/pfx...yMessages&tsn=1&tid=23839&webtag=ws-msdevapps

Ken Sheridan
Stafford, England

Hi,
I have a date field in a form. But I need the default value of that field is
add one day in the next new record.

How can I do that.

like : the last record date value is "31/1/2009" but the default value in
the next new record might be "1/2/2009".

thanks,
 

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