Solved

VBA Query won't Edit

Posted on 2016-08-31
8
52 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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 37

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 37

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
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…

739 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