Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Access Form "Database engine could not lock table"

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
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…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

828 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