Creating a DSN-less, updatable SQL Server linked table in Access 2007

jdallen75
jdallen75 used Ask the Experts™
on
In Access 2007, I've created a DSN-less connection to a SQL Server 2008 R2 table, to create a linked table which I've dropped into an Access form. I followed this MS link:

http://support.microsoft.com/kb/892490

In VBA, I used the Form_Open event to call "AttachDSNLessTable" as outline in the KB article.

Q1: I see "Recordset is not updateable", and it won't let me edit the recordset. I'm assuming it doesn't maintain connection to the SQL table. How do I change this so I can add/edit/delete records in this linked table (and thus have them automatically propogate to the SQL table)?

Q2: From VBA, I'd like to be able to update this linked table in certain spots in a procedure. How do I do so?

I suspect these 2 questions are related. Thanks.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2015
Distinguished Expert 2018

Commented:
Q1: You probably missed to add a Timestamp field in the SQL Server table and relink it.

Q2: Like any other recordset using DAO.

/gustav

Author

Commented:
There is a timestamp field, but the records are not necessarily unique on that field (it's an "edited" field). How does that affect this?

I'm using ADO currently... How does this differ from DAO in this case?
Dale FyeOwner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010

Commented:
You will also need a primary key in the table in order to edit it from Access.
How to Generate Services Revenue the Easiest Way

This Tuesday! Learn key insights about modern cyber protection services & gain practical strategies to skyrocket business:

- What it takes to build a cloud service portfolio
- How to determine which services will help your unique business grow
- Various use-cases and examples

Author

Commented:
Thanks, fyed. That's probably it ... I didn't create the table :-P

Author

Commented:
I found the problem: Access can't handle bigint datatypes, which is what the primary key was identified with.

That takes care of Q1.

I'm still having an issue with Q2: namely, I'd like to be able to update the linked table (the same as going through the Linked Table Manager, selecting the linked table, and updating manually), but through VBA code. I've come across dozens of blogs and nothing seems to update.

I'd like this so if Access has been open for some time, the user can click a Refresh button to ensure that what they see on screen is true to the SQL table.
Most Valuable Expert 2015
Distinguished Expert 2018

Commented:
For that you only need to requery the recordset of the form the user is watching.

Relinking is only needed when schema changes (adding/modifying fields etc.) have taken place.

/gustav

Author

Commented:
Gustav,

Any idea what that syntax would look like? I ask because I tried a few methods, one of which used a ".RefreshLink" or ".Refresh"(?) and the table didn't update when an underlying record change had happened.
Most Valuable Expert 2015
Distinguished Expert 2018
Commented:
It is method Requery.

Method RefreshLink is for refreshing linked tables when the connection string has changed.

/gustav

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial