I do not know VBA syntax or how to properly set up programming using VBA code in MS Access.
I would like to automate changes to two records in the database depending on the current date. The situation is that I have two records for one person (each with a different primary auto number field). Each of the two records has a different address for mailing purposes. There is a winter residence and a summer residence. When I prepare a mailing list, I archive the inactive address, depending on the current date, and the active address only is included on the mailing list.
So I would like the VBA code to do the following:
;;REM summer address
If membershipID=12345 ((if date > 04/30/2012 and date < 12/01/2012) set Archived=false, else set Archived=true)
;;REM winter address
If membershipID=67890 ((if date > 04/30/2012 and date < 12/01/2012) set Archived=true, else set Archived=false)
Can the date be used with MMDD only without YYYY so that the code would not have to be edited each year?
Also, how do I enter the VBA code into the database.
--------------------------------------------------------------
NOTE: I already have some unrelated code in this database. The code was written for me with instructions for its insertion, a few years ago. At this point, I don't remember the steps taken to enter the code into the database. But in this case, the code is linked to a form and only activates if I add or edit a record.
It is shown as a Microsoft Office Access Class Objects/Form frmMembership.
It inserts the current date into the AddDate field when a new record is created. The EditDate field has the current date inserted when there is an edit to an existing record.
this is the unrelated code that already exists in this database:
Option Compare Database
Option Explicit
Private Sub AddDate_BeforeUpdate(Cancel As Integer)
End Sub
Private Sub EditDate_AfterUpdate()
End Sub
Private Sub EditDate_BeforeUpdate(Cancel As Integer)
End Sub
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.Dirty Then
Me![EditDate] = Date
End If
End Sub
------------------------------------------------------------------------------------------------
However, in both cases, I manually have to post something in a record for the VBA codes to activate.
What I want now, if for the two records to automatically update the Archived field whenever the database is opened -- that is, I don't want to have to remember to do anything to the two records based on the date. I want VBA code to have the database do this automatically whenever the database is opened.
Thanks.
Allan
I would like to automate changes to two records in the database depending on the current date. The situation is that I have two records for one person (each with a different primary auto number field). Each of the two records has a different address for mailing purposes. There is a winter residence and a summer residence. When I prepare a mailing list, I archive the inactive address, depending on the current date, and the active address only is included on the mailing list.
So I would like the VBA code to do the following:
;;REM summer address
If membershipID=12345 ((if date > 04/30/2012 and date < 12/01/2012) set Archived=false, else set Archived=true)
;;REM winter address
If membershipID=67890 ((if date > 04/30/2012 and date < 12/01/2012) set Archived=true, else set Archived=false)
Can the date be used with MMDD only without YYYY so that the code would not have to be edited each year?
Also, how do I enter the VBA code into the database.
--------------------------------------------------------------
NOTE: I already have some unrelated code in this database. The code was written for me with instructions for its insertion, a few years ago. At this point, I don't remember the steps taken to enter the code into the database. But in this case, the code is linked to a form and only activates if I add or edit a record.
It is shown as a Microsoft Office Access Class Objects/Form frmMembership.
It inserts the current date into the AddDate field when a new record is created. The EditDate field has the current date inserted when there is an edit to an existing record.
this is the unrelated code that already exists in this database:
Option Compare Database
Option Explicit
Private Sub AddDate_BeforeUpdate(Cancel As Integer)
End Sub
Private Sub EditDate_AfterUpdate()
End Sub
Private Sub EditDate_BeforeUpdate(Cancel As Integer)
End Sub
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.Dirty Then
Me![EditDate] = Date
End If
End Sub
------------------------------------------------------------------------------------------------
However, in both cases, I manually have to post something in a record for the VBA codes to activate.
What I want now, if for the two records to automatically update the Archived field whenever the database is opened -- that is, I don't want to have to remember to do anything to the two records based on the date. I want VBA code to have the database do this automatically whenever the database is opened.
Thanks.
Allan