Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1994
  • Last Modified:

Access Form "Database engine could not lock table"

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
minamina6
Asked:
minamina6
  • 2
1 Solution
 
mbizupCommented:
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
 
minamina6Author Commented:
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
 
mbizupCommented:
<It was bound to the table>

That would do it.

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

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now