Discussion Locked

VB6

0 helpful
7 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

How do I write the code for a Loop that:
1. Opens a database
2. uses a timer object of 10 secs
3. checks if the DB has been updated (date)
4. checks for duplicate numbers using SQL
5. if yes uses msgbox

7 replies

by andrew

Here's a brief example:

Private Sub Form_Load()
Timer1.Interval = 10000 '10 seconds
Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
Dim oCon As ADODB.Connection
Dim oRs As ADODB.Recordset
Static LastUpdate As DateSet oCon = New ADODB.Connection
oCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\WINNT\Profiles\awilliams\Desktop\avg.mdb;"
Set oRs = New Recordset
oRs.Open "SELECT LastUpdated FROM Table3", oCon
If oRs.Fields("LastUpdated").Value > LastUpdated Then
MsgBox "Data has been updated!"
LastUpdated = oRs.Fields("LastUpdated").Value 'cache the vlaue for the next check
End If

oRs.Close
Set oRs = Nothing
Set oCon = Nothing
End Sub

by andrew

For detecting duplicate values, you can use a query like:

SELECT Distinct Data1 from Table3

If this returns more than 1 row (you can use the Recordset.Rowcount property) there are duplicates in the field you specified (Data1 in this example)

by mark.thomson

to check for duplicates using SQL use a query something like this

SELECT Count(number) AS CountOfnumber
FROM table1
GROUP BY table1.number
HAVING (((Count(table1.number))>1))

This discussion is closed to new replies.