Default value of date field based on another

  • Thread starter Thread starter Ed Cones
  • Start date Start date
E

Ed Cones

The user inputs a Purchase Date for a piece of equipment, and I'd like to
default the next field, Warranty Expiration, to Purchase Date plus three
years. The user could still change it in the event that warranty on that
piece is not actually 3 years.

I'm not sure the best way to accomplish this.

thx
 
In the AfterUpdate event of the PurchaseDate field, put code like:

Private Sub PurchaseDate_AfterUpdate

Me![WarranyExpiration].DefaultValue = DateAdd("yyyy", 3,
Me.[PurchaseDate])

End Sub
 
Hmmm.....

I tried the following, and nothing happens when I tab from "Purchase Date"
into "Warranty Expiration", but when I add another record "Warranty
Expiration" defaults to 12/30/1899 as soon as the form opens.

Private Sub Purchase_Date_AfterUpdate()
Me.[Warranty_Expiration].DefaultValue = DateAdd("yyyy", 3,
Me.[Purchase_Date])

End Sub


Douglas J. Steele said:
In the AfterUpdate event of the PurchaseDate field, put code like:

Private Sub PurchaseDate_AfterUpdate

Me![WarranyExpiration].DefaultValue = DateAdd("yyyy", 3,
Me.[PurchaseDate])

End Sub

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Ed Cones said:
The user inputs a Purchase Date for a piece of equipment, and I'd like to
default the next field, Warranty Expiration, to Purchase Date plus three
years. The user could still change it in the event that warranty on that
piece is not actually 3 years.

I'm not sure the best way to accomplish this.

thx
 
Since DefaultValue is a text property (regardless of what type of data the
value may be), see whether this works any better:

Private Sub Purchase_Date_AfterUpdate()

Me.[Warranty_Expiration].DefaultValue = Chr$(34) & DateAdd("yyyy", 3,
Me.[Purchase_Date]) & Chr$(34)

End Sub

Chr$(34) returns a double quote.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Ed Cones said:
Hmmm.....

I tried the following, and nothing happens when I tab from "Purchase Date"
into "Warranty Expiration", but when I add another record "Warranty
Expiration" defaults to 12/30/1899 as soon as the form opens.

Private Sub Purchase_Date_AfterUpdate()
Me.[Warranty_Expiration].DefaultValue = DateAdd("yyyy", 3,
Me.[Purchase_Date])

End Sub


Douglas J. Steele said:
In the AfterUpdate event of the PurchaseDate field, put code like:

Private Sub PurchaseDate_AfterUpdate

Me![WarranyExpiration].DefaultValue = DateAdd("yyyy", 3,
Me.[PurchaseDate])

End Sub

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Ed Cones said:
The user inputs a Purchase Date for a piece of equipment, and I'd like
to
default the next field, Warranty Expiration, to Purchase Date plus
three
years. The user could still change it in the event that warranty on
that
piece is not actually 3 years.

I'm not sure the best way to accomplish this.

thx
 
Progress! This returns the correct date three years from now, but it's still
in the next record I add instead of the next record I add -- not the current
record I'm working in.

Douglas J. Steele said:
Since DefaultValue is a text property (regardless of what type of data the
value may be), see whether this works any better:

Private Sub Purchase_Date_AfterUpdate()

Me.[Warranty_Expiration].DefaultValue = Chr$(34) & DateAdd("yyyy", 3,
Me.[Purchase_Date]) & Chr$(34)

End Sub

Chr$(34) returns a double quote.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Ed Cones said:
Hmmm.....

I tried the following, and nothing happens when I tab from "Purchase Date"
into "Warranty Expiration", but when I add another record "Warranty
Expiration" defaults to 12/30/1899 as soon as the form opens.

Private Sub Purchase_Date_AfterUpdate()
Me.[Warranty_Expiration].DefaultValue = DateAdd("yyyy", 3,
Me.[Purchase_Date])

End Sub


Douglas J. Steele said:
In the AfterUpdate event of the PurchaseDate field, put code like:

Private Sub PurchaseDate_AfterUpdate

Me![WarranyExpiration].DefaultValue = DateAdd("yyyy", 3,
Me.[PurchaseDate])

End Sub

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


The user inputs a Purchase Date for a piece of equipment, and I'd like
to
default the next field, Warranty Expiration, to Purchase Date plus
three
years. The user could still change it in the event that warranty on
that
piece is not actually 3 years.

I'm not sure the best way to accomplish this.

thx
 
Ah! Made it work this way. Thanks for getting me pointed in the right
direction.

Private Sub Purchase_Date_AfterUpdate()
If IsNull(Me.[Warranty_Expiration]) Then
Me.[Warranty_Expiration] = DateAdd("yyyy", 3, Me.[Purchase_Date])
End If
End Sub


Douglas J. Steele said:
Since DefaultValue is a text property (regardless of what type of data the
value may be), see whether this works any better:

Private Sub Purchase_Date_AfterUpdate()

Me.[Warranty_Expiration].DefaultValue = Chr$(34) & DateAdd("yyyy", 3,
Me.[Purchase_Date]) & Chr$(34)

End Sub

Chr$(34) returns a double quote.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Ed Cones said:
Hmmm.....

I tried the following, and nothing happens when I tab from "Purchase Date"
into "Warranty Expiration", but when I add another record "Warranty
Expiration" defaults to 12/30/1899 as soon as the form opens.

Private Sub Purchase_Date_AfterUpdate()
Me.[Warranty_Expiration].DefaultValue = DateAdd("yyyy", 3,
Me.[Purchase_Date])

End Sub


Douglas J. Steele said:
In the AfterUpdate event of the PurchaseDate field, put code like:

Private Sub PurchaseDate_AfterUpdate

Me![WarranyExpiration].DefaultValue = DateAdd("yyyy", 3,
Me.[PurchaseDate])

End Sub

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


The user inputs a Purchase Date for a piece of equipment, and I'd like
to
default the next field, Warranty Expiration, to Purchase Date plus
three
years. The user could still change it in the event that warranty on
that
piece is not actually 3 years.

I'm not sure the best way to accomplish this.

thx
 
Actually, in retrospect that makes more sense than my suggestion!

Mine would be the way to go if you had a bunch of purchases all on the same
day. Yours makes more sense in your case.

Sorry to have led you (slightly) astray!

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Ed Cones said:
Ah! Made it work this way. Thanks for getting me pointed in the right
direction.

Private Sub Purchase_Date_AfterUpdate()
If IsNull(Me.[Warranty_Expiration]) Then
Me.[Warranty_Expiration] = DateAdd("yyyy", 3, Me.[Purchase_Date])
End If
End Sub


Douglas J. Steele said:
Since DefaultValue is a text property (regardless of what type of data
the
value may be), see whether this works any better:

Private Sub Purchase_Date_AfterUpdate()

Me.[Warranty_Expiration].DefaultValue = Chr$(34) & DateAdd("yyyy", 3,
Me.[Purchase_Date]) & Chr$(34)

End Sub

Chr$(34) returns a double quote.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Ed Cones said:
Hmmm.....

I tried the following, and nothing happens when I tab from "Purchase
Date"
into "Warranty Expiration", but when I add another record "Warranty
Expiration" defaults to 12/30/1899 as soon as the form opens.

Private Sub Purchase_Date_AfterUpdate()
Me.[Warranty_Expiration].DefaultValue = DateAdd("yyyy", 3,
Me.[Purchase_Date])

End Sub


:

In the AfterUpdate event of the PurchaseDate field, put code like:

Private Sub PurchaseDate_AfterUpdate

Me![WarranyExpiration].DefaultValue = DateAdd("yyyy", 3,
Me.[PurchaseDate])

End Sub

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


The user inputs a Purchase Date for a piece of equipment, and I'd
like
to
default the next field, Warranty Expiration, to Purchase Date plus
three
years. The user could still change it in the event that warranty on
that
piece is not actually 3 years.

I'm not sure the best way to accomplish this.

thx
 
Your post was far more helpful than not. It stopped me messing with the
Warranty Expiration field and got me to looking at the Purchase Date. Thanks
again.

Douglas J. Steele said:
Actually, in retrospect that makes more sense than my suggestion!

Mine would be the way to go if you had a bunch of purchases all on the same
day. Yours makes more sense in your case.

Sorry to have led you (slightly) astray!

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Ed Cones said:
Ah! Made it work this way. Thanks for getting me pointed in the right
direction.

Private Sub Purchase_Date_AfterUpdate()
If IsNull(Me.[Warranty_Expiration]) Then
Me.[Warranty_Expiration] = DateAdd("yyyy", 3, Me.[Purchase_Date])
End If
End Sub


Douglas J. Steele said:
Since DefaultValue is a text property (regardless of what type of data
the
value may be), see whether this works any better:

Private Sub Purchase_Date_AfterUpdate()

Me.[Warranty_Expiration].DefaultValue = Chr$(34) & DateAdd("yyyy", 3,
Me.[Purchase_Date]) & Chr$(34)

End Sub

Chr$(34) returns a double quote.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Hmmm.....

I tried the following, and nothing happens when I tab from "Purchase
Date"
into "Warranty Expiration", but when I add another record "Warranty
Expiration" defaults to 12/30/1899 as soon as the form opens.

Private Sub Purchase_Date_AfterUpdate()
Me.[Warranty_Expiration].DefaultValue = DateAdd("yyyy", 3,
Me.[Purchase_Date])

End Sub


:

In the AfterUpdate event of the PurchaseDate field, put code like:

Private Sub PurchaseDate_AfterUpdate

Me![WarranyExpiration].DefaultValue = DateAdd("yyyy", 3,
Me.[PurchaseDate])

End Sub

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


The user inputs a Purchase Date for a piece of equipment, and I'd
like
to
default the next field, Warranty Expiration, to Purchase Date plus
three
years. The user could still change it in the event that warranty on
that
piece is not actually 3 years.

I'm not sure the best way to accomplish this.

thx
 
Back
Top