Solved

Access Form "Database engine could not lock table"

Posted on 2013-01-09
3
1,714 Views
Last Modified: 2013-01-09
I am trying to add columns to a table using information gathered from a form.  I keep getting the error "The database engine could not lock table because it is already in use...."
What am I missing?

Private Sub Command0_Click()

Dim TableName As String
Dim ColumnName As String
Dim DataType As String
Dim AddColumn As String

TableName = "ALTER TABLE" & " " & Me.textBox1
ColumnName = "ADD COLUMN" & " " & Me.textBox2
DataType = Me.textBox3 & ";"

AddColumn = TableName & " " & ColumnName & " " & DataType
DoCmd.RunSQL AddColumn

End Sub

Open in new window

0
Comment
Question by:minamina6
  • 2
3 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 50 total points
ID: 38760726
Your code works (I verified it).

However, you need to make sure that your form is not bound to the table you are trying to alter, that the table is not open, and that no one else is using the table.

Also, it's not clear where you are running this code, but I don't think it will work in a shared database.
0
 

Author Comment

by:minamina6
ID: 38760741
A ha! It was bound to the table. I knew the table wasn't open and since I just created the database this afternoon, I knew no one else was in it.
Thank you for your help.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 38760749
<It was bound to the table>

That would do it.

Your bound form effectively is "someone using the table"  :-)
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Pass Variables from Vba access to SQL Query 1 30
Filter Date on Split Form 8 30
Access table Index ignoring Nulls when set to No 3 23
Union & Crosstab qrys 101! 6 53
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

713 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