Solved

rename table column names runtime error

Posted on 2010-09-06
6
473 Views
Last Modified: 2013-11-27
on this line
con.open currentproject.accessconnection

I get runtime error '-2147467259 (80004005)':

the database has been placed in a state by user 'admin' on machine
'fuj1' that prevents it from being opened or locked.




Private Sub Command6_Click()



   'Create a Catalog object

   

   Dim con As New ADODB.Connection

   con.Open CurrentProject.AccessConnection

   

   Dim Cat As New ADOX.Catalog

   Cat.ActiveConnection = con

 

 Dim oldn As String

 Dim newn As String

 Dim tbln As String

 

tbln = "test"

oldn = "dog101"

newn = "dog"



   'Create a table object

   

   Dim Tbl As ADOX.Table

   Set Tbl = New ADOX.Table

  

   Set Tbl = Cat.Tables(tbln)

   Tbl.Columns(oldn).Name = newn

 

   Set Cat = Nothing

   Set Tbl = Nothing





End Sub

Open in new window

0
Comment
Question by:slothnet
6 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 33613965
how about using dao to change it eg

 CurrentDb.TableDefs(tbln).Fields(oldn).Name = newn
0
 
LVL 3

Expert Comment

by:fabalou
ID: 33614027
Check that there is no pending saves to be done to the schema before that code runs. If there is anything that needs to be saved (code edits), form edits e.t.c it can all produce that error.
0
 

Author Comment

by:slothnet
ID: 33614064
I restarted the database and now I get run-time error 3251

object or provider is not capable of performing requested operation
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

Author Comment

by:slothnet
ID: 33614066
on this line

  Tbl.Columns(oldn).Name = newn
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
ID: 33614083


test thiscodes

Dim oldn As String
Dim newn As String
Dim tbln As String
Dim tbl As ADOX.Table
Dim cat As New ADOX.Catalog
Set cat.ActiveConnection = CurrentProject.Connection
 
tbln = "test"
oldn = "dog101"
newn = "dog"
cat.Tables(tbln).Columns(oldn).Name = newn
 
   Set cat = Nothing
   Set tbl = Nothing
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 33614097
and how did you define tbl? I showed you a dao example so tbl as to be defined as dao.tabledef

the code I gave is not compatible with using adox
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
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…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

911 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now