VBA Query won't Edit

Laurence Martin
Laurence Martin used Ask the Experts™
on
Can someone point out why this code crashes at the .Edit saying  that the database or query is read-only?

The code is set in an Access 2010 front-end linked to a SQL Server database.

The Access file is not read only - lots of similar procedures run OK.

The dataset the query produces is updateable - i can open it manually and change the DistributeOrderCard field.



Sub TestCust()
Dim db As Database
Dim recust As Recordset

Set db = CurrentDb()

'open customers
    Set recCust = db.OpenRecordset("qry101DistNewOrderCards", dbOpenDynaset, dbSeeChanges)
'test
    recCust.Edit
    recCust![DistributeOrderCard] = False
    recCust.Update
End Sub
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
I'm thinking about the tables or views that you are accessing on the SQL Server side. Do you have permissions to do more than just read?

Also certain types of queries are always read only. Then there is Access Secuirty permissions and SQL Server Security perms
Top Expert 2016

Commented:
also, see if your query "qry101DistNewOrderCards" falls in the items listed from this link
When can I update data from a query?
Laurence MartinTraining Director

Author

Commented:
Ah yes, the query is Dynaset (inconsistent updates).  Is there a way of making it updateable via VBA.
Acronis in Gartner 2019 MQ for datacenter backup

It is an honor to be featured in Gartner 2019 Magic Quadrant for Datacenter Backup and Recovery Solutions. Gartner’s MQ sets a high standard and earning a place on their grid is a great affirmation that Acronis is delivering on our mission to protect all data, apps, and systems.

LJKMartin: First make sure permissions are set to allow it in SQL Server and in Access.  Is this VBA inside of Access itself?
Distinguished Expert 2017

Commented:
Open the query in datasheet view.  Can you update rows?  If you can't then you can't use the query in VBA as an editable recordsource.

What is making the query not updateable?
Laurence MartinTraining Director

Author

Commented:
Yes, I can open the query in datasheet view and edit, but only because it's Dynaset (inconsistent updates).

The option in VBA is dbOpenDynaset, so I guess that's not allowing inconsistent updates.  Is there an option that allows inconsistent updates?

The query selects from another that has outer joins - which makes it not updateable.

I'm not sure what permissions I need to check, but there are dozens of other queries that work fine, so I'll be surprised if it's that.
Distinguished Expert 2017
Commented:
Help for Access has gotten progressively worse since its peak with A97 but strangely enough, Help actually gives you this answer.

https://msdn.microsoft.com/en-us/library/office/ff820966.aspx
Laurence MartinTraining Director

Author

Commented:
Thanks Pat,

Who'd have thought that Help would actually have the answer!

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