Default value of date 1 day more than previous records value?

  • Thread starter Thread starter Jason M Canady
  • Start date Start date
J

Jason M Canady

I am trying to set the value of a date field (MRDATE) to one day higher than
the previous records entry. I am using the forms On-Open event to go to a
new record, but I would very much like to have the date field already
entered for my operators. I have experimented with different expressions
including DateAdd, and just adding 1 to the MRDATE field. I even tried
going bact to the After_Update event of the MRDATE field but cannot get
something to work.

As usual, any suggestions would be appreciated.

Jason
 
I am trying to set the value of a date field (MRDATE) to one day higher than
the previous records entry. I am using the forms On-Open event to go to a
new record, but I would very much like to have the date field already
entered for my operators. I have experimented with different expressions
including DateAdd, and just adding 1 to the MRDATE field. I even tried
going bact to the After_Update event of the MRDATE field but cannot get
something to work.

Probably the simplest way to do this is to set the control's Default
property in its AfterUpdate event:

Private Sub MRDATE_AfterUpdate()
Me!MRDATE.Default = Chr(34) & Me!MRDATE & Chr(34)
End Sub

The Default property must be a text string, hence the quotes (Chr(34)
is ").
 
John, thanks for the reply. I found modified the code you posted as follows
to obtain the result that I wanted:

Me.MRDATE.DefaultValue = """" & DateAdd("d", 1, (Me.MRDATE.Value)) & """"

However, if I could bother you for some more advice. I do not want to put
this in the afterupdate as that does not give mea value for a new record.
So I have put it in the forms Open event, but that only works once and then
the date does not increment any more. I am wondering where the best place
to put this code really is?

The full code that I am using is:
DoCmd.GoToRecord , , acLast
Me.MRDATE.DefaultValue = """" & DateAdd("d", 1, (Me.MRDATE.Value)) &
""""
DoCmd.GoToRecord , , acNewRec
Which goes to the last record, gets the date, adds one day to it and sets
that to the default for the next record. How do I get this procedure to
repeat for the next record I add? Any ideas?

Thanks for your input.
Jason
 
John, thanks for the reply. I found modified the code you posted as follows
to obtain the result that I wanted:

Me.MRDATE.DefaultValue = """" & DateAdd("d", 1, (Me.MRDATE.Value)) & """"

However, if I could bother you for some more advice. I do not want to put
this in the afterupdate as that does not give mea value for a new record.
So I have put it in the forms Open event, but that only works once and then
the date does not increment any more. I am wondering where the best place
to put this code really is?

I'm not sure I understand what you want the default to be! Do you want
it to be one day later than the date of the most recently entered
record? one larger than the latest date in the table, whenever that
was entered? or what?

The AfterUpdate event will succeed in setting the default for the NEXT
record entered to one day later than the entry in the current record:
so if the user enters a series of dates, they'll only need to type in
a date once. To get the default to be one day later than the largest
date in the table, use the Form's BeforeInsert event instead and
explicitly set the date field:

Me!MRDATE = DateAdd("d", 1, DMax([tablename].[MRDATE]))
 
Thats IT!!! that is exactly what I was working at!! I think I may have
gotten there in one way or another, but what you describe will get me there
in one step!!

Thanks a ton!

Jason

John Vinson said:
John, thanks for the reply. I found modified the code you posted as follows
to obtain the result that I wanted:

Me.MRDATE.DefaultValue = """" & DateAdd("d", 1, (Me.MRDATE.Value)) & """"

However, if I could bother you for some more advice. I do not want to put
this in the afterupdate as that does not give mea value for a new record.
So I have put it in the forms Open event, but that only works once and then
the date does not increment any more. I am wondering where the best place
to put this code really is?

I'm not sure I understand what you want the default to be! Do you want
it to be one day later than the date of the most recently entered
record? one larger than the latest date in the table, whenever that
was entered? or what?

The AfterUpdate event will succeed in setting the default for the NEXT
record entered to one day later than the entry in the current record:
so if the user enters a series of dates, they'll only need to type in
a date once. To get the default to be one day later than the largest
date in the table, use the Form's BeforeInsert event instead and
explicitly set the date field:

Me!MRDATE = DateAdd("d", 1, DMax([tablename].[MRDATE]))
 
Back
Top