Solved

Access Form "Database engine could not lock table"

Posted on 2013-01-09
3
1,542 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

760 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

17 Experts available now in Live!

Get 1:1 Help Now