Solved

VBA Query won't Edit

Posted on 2016-08-31
8
49 Views
Last Modified: 2016-09-07
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
0
Comment
Question by:LJKMartin
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 25

Expert Comment

by:SStory
ID: 41778170
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
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 41778186
also, see if your query "qry101DistNewOrderCards" falls in the items listed from this link
When can I update data from a query?
0
 

Author Comment

by:LJKMartin
ID: 41778328
Ah yes, the query is Dynaset (inconsistent updates).  Is there a way of making it updateable via VBA.
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
LVL 25

Expert Comment

by:SStory
ID: 41778465
LJKMartin: First make sure permissions are set to allow it in SQL Server and in Access.  Is this VBA inside of Access itself?
0
 
LVL 36

Expert Comment

by:PatHartman
ID: 41780579
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?
0
 

Author Comment

by:LJKMartin
ID: 41783553
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.
0
 
LVL 36

Accepted Solution

by:
PatHartman earned 500 total points
ID: 41786593
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
0
 

Author Closing Comment

by:LJKMartin
ID: 41787685
Thanks Pat,

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

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question