• The following corrected code is used just to calculate the days to the next birthday only from dates within a SqlCe database, it is not being used to calculate the age in years. As I am using Sql Compact Edition I do not know of any other method to incorporate Sql except in code. I would therefore be pleased to see your updated version of my code without embedded Sql and exactly where the Sql would be called from. The code below now does what I expected it to do. It may not be the best way, certainly it is not the only way, it is my way and part of my learning curve.

    Imports System

    Imports System.Data

    Imports System.Data.SqlServerCe

    Imports System.Text

    Imports System.IO

    Imports System.ComponentModel

    Imports System.Windows.Forms

    Public Class frmKSBCards

    Dim cn As SqlCeConnection

    Dim PersonsCommand As SqlCeCommand

    Dim PersonsTable As DataTable

    Dim PersonsAdapter As SqlCeDataAdapter

    Public strWarnings As StringBuilder

    Private Sub frmKSBCards_Load(ByVal sender As System.Object,

    ByVal e As System.EventArgs) Handles MyBase.Load

    'connect to the database

    Try

    cn = New SqlCeConnection("Data Source=|DataDirectory|DAL\Contacts.sdf")

    cn.Open()

    Catch sqlex As SqlCeException

    Dim SqlError As SqlCeError

    For Each SqlError In sqlex.Errors

    MessageBox.Show(SqlError.Message)

    Next

    Catch ex As Exception

    MessageBox.Show(ex.Message)

    End Try

    'Select/Retrieve(records)

    Dim Sql As String = "SELECT * FROM Persons ORDER BY Dob" 'Surname, P.Firstname, P.Dob, " &

    PersonsCommand = New SqlCeCommand(Sql, cn)

    PersonsAdapter = New SqlCeDataAdapter()

    PersonsAdapter.SelectCommand = PersonsCommand

    PersonsTable = New DataTable()

    Dim ds As New DataSet

    PersonsAdapter.Fill(ds)

    dgv.DataSource = ds.Tables(0)

    strWarnings = New StringBuilder

    With tmrReminders

    .Interval = 1000 * 60 * 20

    End With

    CheckRenewals()

    End Sub

    Private Sub CheckRenewals()

    With tmrReminders

    .Enabled = False

    PersonsAdapter.Fill(PersonsTable)

    'Get Birthday and Anniversary dates

    Dim PersonDatesView As DataView = PersonsTable.DefaultView

    With PersonDatesView

    If .Count > 0 Then

    Dim bFoundBirthdaysToRemember As Boolean = False

    Dim sBirthdayReminders As String = vbNullString

    For BirthdayCheckCounter As Integer = 0 To .Count - 1

    With .Item(BirthdayCheckCounter)

    Dim PersonBirthday As Date = CType(.Item("Dob"), Date)

    Dim PersonBirthDate As Date = CType(PersonBirthday.Day & "/" & PersonBirthday.Month & "/" & Now.Year, Date)

    Dim NoOfDays As Long = DateDiff(DateInterval.Day, Now, PersonBirthDate) + 1

    'Test For Dob

    If NoOfDays < 10 Then

    If NoOfDays > -10 And NoOfDays < 0 Then

    ElseIf NoOfDays > -1 Then

    bFoundBirthdaysToRemember = True

    If sBirthdayReminders <> vbNullString Then _

    sBirthdayReminders &= vbCrLf

    Dim DayString As String = IIf(NoOfDays = 1, " day", " days").ToString

    sBirthdayReminders &= .Item("Firstname").ToString.Trim & " " & _

    "'s Birthday due in : " & _

    NoOfDays.ToString & DayString

    End If

    End If

    End With

    Next

    If (bFoundBirthdaysToRemember) Then

    With niReminders

    .Visible = True

    If bFoundBirthdaysToRemember Then

    .BalloonTipIcon = ToolTipIcon.Info

    .BalloonTipText = sBirthdayReminders

    .BalloonTipTitle = "Cards Due for Action"

    End If

    .ShowBalloonTip(15)

    End With

    End If

    End If

    End With

    .Enabled = True

    End With

    End Sub

    End Class