Solved

VBA Query won't Edit

Posted on 2016-08-31
8
46 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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
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 35

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 35

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

831 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