Laurence Martin
asked on
VBA Query won't Edit
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("qry101Di stNewOrder Cards", dbOpenDynaset, dbSeeChanges)
'test
recCust.Edit
recCust![DistributeOrderCa rd] = False
recCust.Update
End Sub
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("qry101Di
'test
recCust.Edit
recCust![DistributeOrderCa
recCust.Update
End Sub
also, see if your query "qry101DistNewOrderCards" falls in the items listed from this link
When can I update data from a query?
When can I update data from a query?
ASKER
Ah yes, the query is Dynaset (inconsistent updates). Is there a way of making it updateable via VBA.
LJKMartin: First make sure permissions are set to allow it in SQL Server and in Access. Is this VBA inside of Access itself?
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?
What is making the query not updateable?
ASKER
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Pat,
Who'd have thought that Help would actually have the answer!
Who'd have thought that Help would actually have the answer!
Also certain types of queries are always read only. Then there is Access Secuirty permissions and SQL Server Security perms