Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am completely new to Access (have some experience with SQL server).

I am not sure if its even possible in MS Access 2010: if for one of table.dateField is today or earlier - need to send email about that record.

Extensive digging doesn't bring any results, seems its not feasible, but wanted group opinion on that. Thank you

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
337 views
Welcome To Ask or Share your Answers For Others

1 Answer

The Microsoft Access application does not have any built-in feature to automatically scan the database and send email messages based on the status of records in a table. However, that does not mean that such a function is "not feasible" for information stored in an Access database. In fact, implementing such a feature could be as simple as this:

The following VBScript code could be run (via cscript.exe) every morning as a Scheduled Task under Windows. It will scan a table named [Patients] and send a "Happy Birthday" message to each person who has a birthday that day.

Option Explicit

Dim con  ' As ADODB.Connection
Dim rst  ' As ADODB.Recordset
Dim msg  ' As CDO.Message

Set con = CreateObject("ADODB.Connection")  ' New ADODB.Connection
con.Open _
        "Provider=Microsoft.ACE.OLEDB.12.0;" & _
        "Data Source=C:UsersGordDesktopDatabase1.accdb;"
Set rst = CreateObject("ADODB.Recordset")  ' New ADODB.Recordset
rst.Open _
        "SELECT FirstName, Email " & _
        "FROM Patients " & _
        "WHERE Month(DOB) = Month(Date()) " & _
            "AND Day(DOB) = Day(Date())", _
        con
Do Until rst.EOF
    Set msg = CreateObject("CDO.Message")  ' New CDO.Message
    msg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    msg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.example.com"
    msg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    msg.Configuration.Fields.Update

    msg.To = rst("Email").Value
    msg.From = "admin@example.com"
    msg.Subject = "Happy Birthday!"
    msg.TextBody = "Hi, " & rst("FirstName").Value & ". We hope you have a great birthday today!"
    msg.Send

    Set msg = Nothing
    rst.MoveNext
Loop
rst.Close
Set rst = Nothing
con.Close
Set con = Nothing

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...