Error when i nìmnodify query in access database via ADOX

User avatar
sal21
PlatinumLounger
Posts: 4368
Joined: 26 Apr 2010, 17:36

Error when i nìmnodify query in access database via ADOX

Post by sal21 »

Code: Select all

Option Explicit
Sub UNO()

Dim cn As Connection, SQL As String
Dim mcat As ADOX.Catalog
Dim mview As ADOX.View
Dim cmd As ADODB.Command

Set cn = New ADODB.Connection

cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\...............ABELLE.mdb"
cn.Open

Set mcat = New ADOX.Catalog
Set mcat.ActiveConnection = cn

Set mview = mcat.Views("CANCELLA_STORIA")
Set cmd = mview.Command

cmd.CommandText = "New SQL Statement goes here"

Set mview.Command = cmd

Set mview = Nothing
Set cmd = Nothing
Set mcat = Nothing

cn.Close
Set cn = Nothing

End Sub

whit this code i have erro in attached image.
Why?

the line in question is:
Set mview = mcat.Views("CANCELLA_STORIA")
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78594
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Error when i nìmnodify query in access database via ADOX

Post by HansV »

The Views collection contains only simple select queries. It does *not* include parameter queries, crosstab queries and action queries. Is CANCELLA_STORIA a simple select query?

(And what is nìmnodify ?) :scratch:
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4368
Joined: 26 Apr 2010, 17:36

Re: Error when i nìmnodify query in access database via ADOX

Post by sal21 »

HansV wrote:The Views collection contains only simple select queries. It does *not* include parameter queries, crosstab queries and action queries. Is CANCELLA_STORIA a simple select query?

(And what is nìmnodify ?) :scratch:
delete query:
"DELETE * FROM VIAGGIANTI_TAB WHERE VIAGGIANTI_TAB.INDICE1='20122010'"

User avatar
HansV
Administrator
Posts: 78594
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Error when i nìmnodify query in access database via ADOX

Post by HansV »

A delete query is not part of the Views collection, but of the Procedures collection. So change

Dim mview As ADOX.View

to

Dim mview As ADOX.Procedure

and change

Set mview = mcat.Views("CANCELLA_STORIA")

to

Set mview = mcat.Procedures("CANCELLA_STORIA")
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4368
Joined: 26 Apr 2010, 17:36

Re: Error when i nìmnodify query in access database via ADOX

Post by sal21 »

HansV wrote:A delete query is not part of the Views collection, but of the Procedures collection. So change

Dim mview As ADOX.View

to

Dim mview As ADOX.Procedure

and change

Set mview = mcat.Views("CANCELLA_STORIA")

to

Set mview = mcat.Procedures("CANCELLA_STORIA")
GENIUS!
:clapping: :thankyou:

User avatar
sal21
PlatinumLounger
Posts: 4368
Joined: 26 Apr 2010, 17:36

Re: Error when i nìmnodify query in access database via ADOX

Post by sal21 »

HansV wrote:A delete query is not part of the Views collection, but of the Procedures collection. So change

Dim mview As ADOX.View

to

Dim mview As ADOX.Procedure

and change

Set mview = mcat.Views("CANCELLA_STORIA")

to

Set mview = mcat.Procedures("CANCELLA_STORIA")
OK...
But is possible to use this line to exc eute the new query edited?
I have used this line but have error.
CN.Execute "CANCELLA_STORIA", CONTA, adCmdText Or adExecuteNoRecords

i know the way rs.open "CANCELLA_STORIA", ecc but i dont need to have recorset, i need to delete

User avatar
HansV
Administrator
Posts: 78594
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Error when i nìmnodify query in access database via ADOX

Post by HansV »

Use

CN.Execute "CANCELLA_STORIA", CONTA, adCmdStoredProc Or adExecuteNoRecords
Best wishes,
Hans