Solved

Access Form "Database engine could not lock table"

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

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

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
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…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

919 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