I'm VERY new at using VBA although I have been programming for many years.
I have a requirement that involves creating a new version of a record and setting the expiry date of the current version to one day less than the effective date of the new version.
Regardless of what I try, the new expiry date that gets set is always 12/30/1899.
I suspect there is something very elementary that I'm missing, but haven't been able to figure out what it might be. Perhaps I need to apply a function to the setExpiryDate variable?
Any suggestions would be appreciated. Here is the current version of the code I'm working with:
Private Sub createNewVersion_Click()
Dim strUpdate As String
Dim intervalType As String
Dim adjustment As Integer
Dim setExpiryDate As Date
Dim newEffDate As Date
intervalType = "d"
adjustment = -1
newEffDate = Forms!fCreateDomainVersion!NewEffectiveDate
setExpiryDate = DateAdd("d", -1, newEffDate)
strUpdate = "UPDATE tDomain " & _
"SET ExpiryDate = " & setExpiryDate & _
" WHERE DomainName = Forms!fCreateDomainVersion!DomainName AND " & _
"EffectiveDate = Forms!fCreateDomainVersion!EffectiveDate;"
DoCmd.RunSQL strUpdate
End Sub
I have a requirement that involves creating a new version of a record and setting the expiry date of the current version to one day less than the effective date of the new version.
Regardless of what I try, the new expiry date that gets set is always 12/30/1899.
I suspect there is something very elementary that I'm missing, but haven't been able to figure out what it might be. Perhaps I need to apply a function to the setExpiryDate variable?
Any suggestions would be appreciated. Here is the current version of the code I'm working with:
Private Sub createNewVersion_Click()
Dim strUpdate As String
Dim intervalType As String
Dim adjustment As Integer
Dim setExpiryDate As Date
Dim newEffDate As Date
intervalType = "d"
adjustment = -1
newEffDate = Forms!fCreateDomainVersion!NewEffectiveDate
setExpiryDate = DateAdd("d", -1, newEffDate)
strUpdate = "UPDATE tDomain " & _
"SET ExpiryDate = " & setExpiryDate & _
" WHERE DomainName = Forms!fCreateDomainVersion!DomainName AND " & _
"EffectiveDate = Forms!fCreateDomainVersion!EffectiveDate;"
DoCmd.RunSQL strUpdate
End Sub