1

I've got code (below) to read data from a MS Access table into MATLAB, via an ActiveX server, that works very nicely. I'm now trying to use the same code to read data from an Access linked table connected to SQL Server, but am getting an error:

Invoke Error, Dispatch Exception: Source: DAO.Database Description: You must use the dbSeeChanges option with OpenRecordset when accessing a SQL Server table that has an IDENTITY column. Help File: jeterr40.chm Help Context ID: 4c5966

So, the table in question has an IDENTITY column, and I need to specify the 'dbSeeChanges' option with OpenRecordset. My question is, how do I specify this option? I can see plenty of examples online of how to do it in VBA, but none that would be MATLAB-compatible. Here's my code:

% Setup environment
app = 'Access.Application';
DBAddress = 'O:\testData.accdb';

% Load an Activex server for Access
try
    svr = actxGetRunningServer(app);
catch err
    svr = actxserver(app);
end

% Load the required database file
accessDB = svr.DBEngine.OpenDatabase(DBAddress);

% Query the database for the required records
sql_query = 'SELECT * FROM dbo_PatientMeasurementResults;';
rs = accessDB.OpenRecordset(sql_query);

I've tried the obvious, but this does not work:

rs = accessDB.OpenRecordset(sql_query,'dbSeeChanges');
2
  • 1
    dbSeeChanges is a number (Const dbSeeChanges = 512 (&H200)). Have you tried rs = accessDB.OpenRecordset(sql_querry, dbSeeChanges); ? (or with the constant 512) Commented Nov 9, 2016 at 14:58
  • Thanks @Andre. dbSeeChanges = 512 gave me an Invoke Error (Description: Invalid argument.) error, but interestingly 'dbSeeChanges = 4 fixed the problem. Haven't got to the bottom yet of why that worked, however! Commented Nov 10, 2016 at 9:40

1 Answer 1

1

Silly me, dbSeeChanges is a value for the Options parameter, which is the third, not the second parameter of OpenRecordset:

Database.OpenRecordset Method (DAO)

What happened now is: Const dbOpenSnapshot = 4 - you opened a "Snapshot" recordset, which is read-only. So dbSeeChanges isn't needed.

If you want to only read from the recordset, than this is indeed the best option (but you should change your constant in your code to avoid future confusion).

To open an editable recordset, use

Const dbOpenDynaset = 2
Const dbSeeChanges = 512
rs = accessDB.OpenRecordset(sql_query, dbOpenDynaset, dbSeeChanges);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.