Re: Store SQL Timestamp locally for comparison
- From: DBG <DBG@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 20 Mar 2006 07:57:28 -0800
Finally had a few free moments, and got everything set up to this point.
Good code sample, very helpful.
Thanks,
-David
"Brian Wilson" wrote:
.
"DBG" <DBG@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:5A931A51-BD48-43F4-97D8-A5556D55A2BB@xxxxxxxxxxxxxxxx
Lest I forget, what do you think is an appropriate database table Data
Type
for storing the timestamp information. Text? Obviously it's only being
stored locally for an exact comparison to what is stored remotely, and I
have
a feeling if I store it in a date/time in Access it will get mangled. I
could be wrong though.
-David
As you know, Access doesn't have the timestamp field, but I believe this
maps to a Binary (8) field. However you cannot create this via the GUI and
you would have to do it in code, nor am I sure whether there is any suitable
substitute.
Anyway, here is an example of the sort of code you could write. It assumes
that all the changes happen to the server dataset so that if a record is
present in the local table but not the linked table then it must have been
deleted from the server (rather than added to the local table). Similarly,
if a record is missing from the local table which is in the linked table,
then this must have been due to adding a record to the server (rather than
deleting from the local table)
Public Sub CompareTables()
On Error GoTo Err_Handler
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
Dim lngRecords As Long
Dim strInfo As String
Set dbs = CurrentDb
' ------------------------------------------------------------------
strSQL = "SELECT Count(*) AS DeletedFromServer " & _
"FROM tblLocal LEFT JOIN tblLinked " & _
"ON tblLocal.ID=tblLinked.ID " & _
"WHERE tblLinked.ID Is Null"
Set rst = dbs.OpenRecordset(strSQL, dbOpenForwardOnly, dbReadOnly)
If Not rst.EOF Then
lngRecords = CLng(rst.Fields(0).Value)
strInfo = strInfo & vbCrLf & CStr(lngRecords) & _
" record(s) have been deleted from the server"
End If
rst.Close
Set rst = Nothing
' ------------------------------------------------------------------
' ------------------------------------------------------------------
strSQL = "SELECT Count(*) AS AddedToServer " & _
"FROM tblLinked LEFT JOIN tblLocal " & _
"ON tblLinked.ID=tblLocal.ID " & _
"WHERE tblLocal.ID Is Null"
Set rst = dbs.OpenRecordset(strSQL, dbOpenForwardOnly, dbReadOnly)
If Not rst.EOF Then
lngRecords = CLng(rst.Fields(0).Value)
strInfo = strInfo & vbCrLf & CStr(lngRecords) & _
" record(s) have been added to the server"
End If
rst.Close
Set rst = Nothing
' ------------------------------------------------------------------
' ------------------------------------------------------------------
strSQL = "SELECT Count(*) AS UpdatedOnServer " & _
"FROM tblLinked INNER JOIN tblLocal " & _
"ON tblLinked.ID=tblLocal.ID " & _
"WHERE tblLocal.MyStamp<>tblLinked.MyStamp"
Set rst = dbs.OpenRecordset(strSQL, dbOpenForwardOnly, dbReadOnly)
If Not rst.EOF Then
lngRecords = CLng(rst.Fields(0).Value)
strInfo = strInfo & vbCrLf & CStr(lngRecords) & _
" record(s) have been updated on the server"
End If
rst.Close
Set rst = Nothing
' ------------------------------------------------------------------
If Len(strInfo) > 2 Then
strInfo = "Assuming the local table has not changed:" & _
vbCrLf & strInfo
End If
MsgBox strInfo, vbInformation
Exit_Handler:
If Not rst Is Nothing Then
rst.Close
Set rst = Nothing
End If
If Not dbs Is Nothing Then
Set dbs = Nothing
End If
Exit Sub
Err_Handler:
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler
End Sub
- References:
- Re: Store SQL Timestamp locally for comparison
- From: Brian Wilson
- Re: Store SQL Timestamp locally for comparison
- From: Brian Wilson
- Re: Store SQL Timestamp locally for comparison
- From: Brian Wilson
- Re: Store SQL Timestamp locally for comparison
- Prev by Date: Re: Error Code 3048/64509
- Next by Date: Re: Build A User Defined STR Statement Using Access 2000
- Previous by thread: Re: Store SQL Timestamp locally for comparison
- Next by thread: Re: Store SQL Timestamp locally for comparison
- Index(es):
Relevant Pages
|
|