JeffBarker
Registered User.
- Local time
- Today, 22:19
- Joined
- Dec 7, 2010
- Messages
- 130
Hi guys,
Yet another random request from me that I'm hoping someone will be able to assist with - this time based around a membership database that we're currently running on behalf of a client.
The database holds around 2,000 members, each with their own expiry date, and each week we email a newsletter to everyone.
At the moment I'm physically running the queries every Friday to extract the info for these emails, and depending on the member expiry date we tailor some of the content that they see.
For example, if their membership expires in the next 21 days then the email header says "you have three weeks until your membership expires", if their membership expires in 14 days the header says "you have two weeks" and so on.
What I need is a code that will run every Friday morning and generate the four queries we need for the newsletter and attach and send them in an email to my colleague - but only if the query has data in it.
I've got the Weekday bit sorted:
My original thought was to run the code on a Friday when the DB is opened, but as both myself and other colleagues will cose and re-open the database many times within a day I understand that the code will run every single time that happens on a Friday.
So I need two things
1) A solution for how to ensure the routine is run only once on a Friday when the DB is first opened by a user
2) A way of only attaching the queries as an Excel spreadsheet if there are records in them
Thanking you all in advance - I shall be working on this myself, so as and when I crack a section I'll report back here!

Yet another random request from me that I'm hoping someone will be able to assist with - this time based around a membership database that we're currently running on behalf of a client.
The database holds around 2,000 members, each with their own expiry date, and each week we email a newsletter to everyone.
At the moment I'm physically running the queries every Friday to extract the info for these emails, and depending on the member expiry date we tailor some of the content that they see.
For example, if their membership expires in the next 21 days then the email header says "you have three weeks until your membership expires", if their membership expires in 14 days the header says "you have two weeks" and so on.
What I need is a code that will run every Friday morning and generate the four queries we need for the newsletter and attach and send them in an email to my colleague - but only if the query has data in it.
I've got the Weekday bit sorted:
Code:
Private Sub cmdWeeklyEmail_Click()
Dim MyDate As Date
Dim MyWeekday As Integer
MyDate = Date
MyWeekday = Weekday(MyDate, vbSunday)
If MyWeekday = vbThursday Then
MsgBox "It's Thursday!"
Else
MsgBox "Code's rubbish"
End If
My original thought was to run the code on a Friday when the DB is opened, but as both myself and other colleagues will cose and re-open the database many times within a day I understand that the code will run every single time that happens on a Friday.
So I need two things
1) A solution for how to ensure the routine is run only once on a Friday when the DB is first opened by a user
2) A way of only attaching the queries as an Excel spreadsheet if there are records in them
Thanking you all in advance - I shall be working on this myself, so as and when I crack a section I'll report back here!