Tom
09-17-2006, 12:43 AM
I used to HATE that prompt! So this is a little info for beginning coders.
Let's say you're going to create a table called "work", so you write this line:
DoCmd.RunSQL "SELECT data.DEPARTMENT_NAME, data.FIRST_NAME, _
data.MIDDLE_INIT INTO [Work] FROM data ORDER BY data.DEPARTMENT_NAME;"
The next time you run it you get the "The existing table will be deleted before you run query" prompt.
OF COURSE YOU KNOW YOU?RE GOING TO DELETE THE TABLE!!
So you add this line above the other:
DoCmd.DeleteObject acTable, "Work"
DoCmd.RunSQL "SELECT data.DEPARTMENT_NAME, data.FIRST_NAME, _
data.MIDDLE_INIT INTO
[Work] FROM data ORDER BY data.DEPARTMENT_NAME;"
Now this works great unless your code stalls out and you have to rerun the script.
What happens?
You get ?Microsoft Office can?t find the object ?work? because the table?s already been deleted.
What do you do? You add this neat little sub routine that tells the system, ?If you find the object ?work? delete it, if not keep on going! And it looks something like this:
Sub CREATE_TABLE
'Put the sub routine call here before the create table SQL
D_WORK
DoCmd.RunSQL "SELECT data.DEPARTMENT_NAME, data.FIRST_NAME, _
data.MIDDLE_INIT INTO [Work] FROM data ORDER BY data.DEPARTMENT_NAME;"
End Sub
And the sub routine runs before the create table script
Sub D_WORK()
Dim DBS
Dim TDF
Dim T
Dim TD
Set DBS = CurrentDb
Set TDF = DBS.TableDefs
For Each TDF In CurrentDb.TableDefs
If TDF.Name = "WORK" Then
DoCmd.DeleteObject acTable, "WORK"
Exit For
End If
Next
End Sub
Anyhooooooo, when I started writing code I had to figure this one out on my own. I hope I can save a novice code writer some heartburn :)
If I've confused anyone, please let me know and I'll try to explain things a blt better.
Let's say you're going to create a table called "work", so you write this line:
DoCmd.RunSQL "SELECT data.DEPARTMENT_NAME, data.FIRST_NAME, _
data.MIDDLE_INIT INTO [Work] FROM data ORDER BY data.DEPARTMENT_NAME;"
The next time you run it you get the "The existing table will be deleted before you run query" prompt.
OF COURSE YOU KNOW YOU?RE GOING TO DELETE THE TABLE!!
So you add this line above the other:
DoCmd.DeleteObject acTable, "Work"
DoCmd.RunSQL "SELECT data.DEPARTMENT_NAME, data.FIRST_NAME, _
data.MIDDLE_INIT INTO
[Work] FROM data ORDER BY data.DEPARTMENT_NAME;"
Now this works great unless your code stalls out and you have to rerun the script.
What happens?
You get ?Microsoft Office can?t find the object ?work? because the table?s already been deleted.
What do you do? You add this neat little sub routine that tells the system, ?If you find the object ?work? delete it, if not keep on going! And it looks something like this:
Sub CREATE_TABLE
'Put the sub routine call here before the create table SQL
D_WORK
DoCmd.RunSQL "SELECT data.DEPARTMENT_NAME, data.FIRST_NAME, _
data.MIDDLE_INIT INTO [Work] FROM data ORDER BY data.DEPARTMENT_NAME;"
End Sub
And the sub routine runs before the create table script
Sub D_WORK()
Dim DBS
Dim TDF
Dim T
Dim TD
Set DBS = CurrentDb
Set TDF = DBS.TableDefs
For Each TDF In CurrentDb.TableDefs
If TDF.Name = "WORK" Then
DoCmd.DeleteObject acTable, "WORK"
Exit For
End If
Next
End Sub
Anyhooooooo, when I started writing code I had to figure this one out on my own. I hope I can save a novice code writer some heartburn :)
If I've confused anyone, please let me know and I'll try to explain things a blt better.