Link to home
Start Free TrialLog in
Avatar of slothnet

asked on

rename table column names runtime error

on this line 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

Avatar of rockiroads
Flag of United States of America image

how about using dao to change it eg

 CurrentDb.TableDefs(tbln).Fields(oldn).Name = newn
Avatar of fabalou

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.
Avatar of slothnet


I restarted the database and now I get run-time error 3251

object or provider is not capable of performing requested operation
on this line

  Tbl.Columns(oldn).Name = newn
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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