Does DAO's Last Modified Really Work? (1 Viewer)

James Dickinson

PigeonPie
Local time
Today, 23:47
Joined
May 10, 2018
Messages
43
The Test:
Confirm that DAO's LastModified function does indeed return YOUR Last Modified record.

Method:
Using 2 Access Front Ends running the same routine and connecting to a single Access Back End table.

Attempt to read back an inserted GUID value that is not the inserted GUID value.

Loop and continue if contention.

Steps:
  1. BACKEND: Create a blank database with a table Named [Bloat] and fields [ID] autonumber and [GUID] short text
  2. FRONT END: Create a blank database add a module and paste the code below.
  3. Copy the FRONT END so there are 2 Front Ends
  4. Link the Back End Table [Bloat] to the Front Ends
  5. Run testingLastModified in both front ends


The following code was used in a Module in the 2 Front End databases each run within a few seconds of the other.


Code:
Option Compare Database
Option Explicit

Private Type GUID_TYPE
                Data1 As Long
                Data2 As Integer
                Data3 As Integer
                Data4(7) As Byte
End Type
Private Declare PtrSafe Function CoCreateGuid Lib "ole32.dll" (Guid As GUID_TYPE) As LongPtr
Private Declare PtrSafe Function StringFromGUID2 Lib "ole32.dll" (Guid As GUID_TYPE, ByVal lpStrGuid As LongPtr, ByVal cbMax As Long) As LongPtr

Function GenerateGUID() As String
10    On Error GoTo PROC_ERR
                Dim Guid As GUID_TYPE
                Dim strGuid As String
                Dim retValue As LongPtr
                Const guidLength As Long = 39
                retValue = CoCreateGuid(Guid)
                If retValue = 0 Then
                                strGuid = String$(guidLength, vbNullChar)
                        retValue = StringFromGUID2(Guid, StrPtr(strGuid), guidLength)
                                If retValue = guidLength Then
                                                ' valid GUID as a string
            GenerateGUID = Mid$(strGuid, 2, 36)  ' removes the braces from the output
                                End If
                End If
PROC_EXIT:
            Exit Function
PROC_ERR:
            MsgBox "Error: " & err.Number & ". " & err.Description
            Resume PROC_EXIT
End Function

Public Function testingLastModified()

   Dim rs As DAO.Recordset
   Dim strKnownGUID As String
   Dim i As Integer, e As Integer
   Dim DB As Database

   On Error GoTo err
   Set DB = CurrentDb

   Do
      Set rs = DB.OpenRecordset("SELECT * from [Bloat]")
      strKnownGUID = GenerateGUID
      rs.AddNew
      rs!Guid = strKnownGUID
      rs.Update
  
      rs.Bookmark = rs.LastModified
      If rs!Guid <> strKnownGUID Then
         MsgBox "Failed wrong GUID!!!!"
      Else
         Debug.Print "Pass", i
      End If

      rs.Close
      DoEvents

      i = i + 1
  
   Loop While (i < 100000)
   Exit Function
err:
   e = e + 1
   DoEvents
   Debug.Print "Contention", i, e
   Resume
End Function

Results:
While contention did occur at times there was no attempt that returned a failed result.
Last Modified was indeed YOUR last modified record under these conditions.
 

NauticalGent

Ignore List Poster Boy
Local time
Today, 06:47
Joined
Apr 27, 2015
Messages
6,286
Very interesting, never hear of the LastModified property. Learn something new everyday...
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 10:47
Joined
Sep 12, 2006
Messages
15,614
Here's a page from my DAO reference book

lastmod1.jpg
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 10:47
Joined
Sep 12, 2006
Messages
15,614
DAO Object Model. Helen Feddema (O'Reilly)
I have the first edition from 2000. I have never had a problem with it. I have never used an msys table directly, and use documented DAO features to manage tables/fields/indexes/querydefs and so on.

ISBN 1-56592-435-5
 
Last edited:

NauticalGent

Ignore List Poster Boy
Local time
Today, 06:47
Joined
Apr 27, 2015
Messages
6,286
I thought I recognized the Wise Owl from O'Reilly...thanks, I give a look over.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 05:47
Joined
Feb 28, 2001
Messages
27,001
I would think that it can only retain this "bookmark" until you close the recordset. In the M$ docs online, it clearly states that the modification has to have occurred using the .Recordset object; it is not related to the last object modified in the table by just any source.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 10:47
Joined
Sep 12, 2006
Messages
15,614
I would think that it can only retain this "bookmark" until you close the recordset. In the M$ docs online, it clearly states that the modification has to have occurred using the .Recordset object; it is not related to the last object modified in the table by just any source.
YEs - that's what it said in the book I have, pictured earlier. Only certain types of recordset also - table & dynaset
 

Users who are viewing this thread

Top Bottom