[quoted text, click to view] "Tony Girgenti" <antoniongirgenti@comcast.net> wrote in message
news:OeD2wd04DHA.2772@TK2MSFTNGP09.phx.gbl...
> I'm reposting this because i tried deleteing the table manually and
> recreating it manually. It works OK after that, but when i try it again, it
> gives the error again. There are four tables, but it only happens on the
> "ITEMS" table.
>
> I'm trying to execute the following code and i am getting this error:
>
> "Run-time error '3211'; The database engine could not lock table 'Items'
> becuase it is already in use by another person or process".
>
> This code is being executed in AccessXP using an ODBC connection to a server
> DB. I'm not sure exactly which statement it is giving the error on.
> All other computers were turned off and the one computer was restarted, but
> we still get the error. The table is not being used by a form.
>
> Any help would be greatly appreciated.
>
> Tony
>
> ============================================================================
> =================================
> CurrentDb.Execute "DROP TABLE Items"
>
> DoCmd.TransferDatabase acImport, "ODBC Database", _
>
> "ODBC;DSN=DEMO2ENG;ArrayFetchOn=1;ArrayBufferSize=8;DBQ=DEMO2ENG;OpenMode=0;
> DecimalSymbol=.;;TABLE=Items", _
> acTable, "Items", "Items"
> CurrentDb.Execute "CREATE UNIQUE INDEX ItemNumIdx ON Items (ItemNumber)"
>
>
>
Hi Tony,
I am assuming you did not want to *link* to
the SQL table?
Would you mind changing your local table
name to "tblItems" then try the following:
'----------------------------
Dim strSQL As String
Debug.Print "About to delete table."
CurrentDb.Execute "DROP TABLE tblItems", dbFailOnError
Debug.Print "Have deleted table."
strSQL = "SELECT Items.* INTO tblItems " _
& "FROM Items IN '' [ODBC;DSN=DEMO2ENG;DATABASE=];"
Debug.Print "Make table query: " & vbCrLf & strSQL
CurrentDb.Execute strSQL, dbFailOnError
Debug.Print "Have executed make table."
Debug.Print "About to create index."
strSQL = "CREATE UNIQUE INDEX ItemNumIdx ON tblItems (ItemNumber);"
CurrentDb.Execute strSQL, dbFailOnError
Debug.Print "Have created index."
'------------------------------
{from tip provided by John Viescas}
To see what needs to go in between the brackets,
temporarily link to remote table "Items," then in
Immediate Window type the following:
?CurrentDb.Tabledefs("Items").Connect
Place whatever this returns inside the brackets,
then delete link to "Items."
Please respond back if I have misunderstood.
Good luck,
Gary Walter