You must use the dbSeeChanges option with OpenRecordSet when accessing a SQL Server t (1 Viewer)

BennyLinton

Registered User.
Local time
Yesterday, 16:53
Joined
Feb 21, 2014
Messages
263
I have a local table "ztblDataChanges" that is working well for the function below, however when i convert this table to a SQL Server table ODBC linked I get the following error... Any ideas?:

You must use the dbSeeChanges option with OpenRecordSet when accessing a SQL Server table that has an IDENTITY column

Code:
Function LogChanges(lngID As Long, Optional strField As String = "")
    Dim dbs As DAO.Database
    Dim rst As DAO.Recordset
    Dim varOld As Variant
    Dim varNew As Variant
    Dim strFormName As String
    Dim strControlName As String

    varOld = Screen.ActiveControl.OldValue
    varNew = Screen.ActiveControl.value
    strFormName = Screen.ActiveForm.Name
    strControlName = Screen.ActiveControl.Name
    Set dbs = CurrentDb()
    Set rst = dbs.TableDefs("ztblDataChanges").OpenRecordset
    With rst
        .AddNew
        !FormName = strFormName
        !ControlName = strControlName
        If strField = "" Then
            !FieldName = strControlName
        Else
            !FieldName = strField
        End If
        !recordid = lngID
        !userName = Environ("username")
        If Not IsNull(varOld) Then
            !OldValue = CStr(varOld)
        End If
        !NewValue = CStr(Nz(varNew, 0))
        .Update
    End With
    'clean up
    rst.close
    Set rst = Nothing
    dbs.close
    Set dbs = Nothing
End Function
 

isladogs

MVP / VIP
Local time
Today, 00:53
Joined
Jan 14, 2017
Messages
18,235
You are editing the data so you do need to add
, dbSeeChanges
at the end of the Set rst line

IDENTITY refers to the pk field
 

BennyLinton

Registered User.
Local time
Yesterday, 16:53
Joined
Feb 21, 2014
Messages
263
I get a syntax error with thei:
Code:
    Set rst = dbs.TableDefs("ztblDataChanges").OpenRecordset, dbSeeChanges
 

isladogs

MVP / VIP
Local time
Today, 00:53
Joined
Jan 14, 2017
Messages
18,235
Hi
Sorry missed out a bit of code.
It should have

... OpenRecordset ... , dbOpenDynaset, dbSeeChanges

Apologies I'm writing this on my phone but this should be ok now if you fill in the ... bits
 

BennyLinton

Registered User.
Local time
Yesterday, 16:53
Joined
Feb 21, 2014
Messages
263
If I use the below it is giving a compile error of "expected end of statement" after .OpenRecordset,
Code:
Set rst = dbs.TableDefs("ztblDataChanges").OpenRecordset, dbOpenDynaset, dbSeeChanges
 

BennyLinton

Registered User.
Local time
Yesterday, 16:53
Joined
Feb 21, 2014
Messages
263
Success! This worked: Thanks!:

Code:
Set rst = dbs.OpenRecordset("ztblDataChanges", dbOpenDynaset, dbSeeChanges)
 

Users who are viewing this thread

Top Bottom