
DELETING TABLE, CREATING NEW TABLE
The easiest way I can think of is as follows.
On Error Resume Next
Set tdfnew = dbsexist.CreateTableDef("NewTable") 'Of course if we
get an error, it's already there
If Error <> "" Then
' If we don't lets build it
With tdfnew
.Fields.Append .CreateField("UserID", dbText)
.Fields.Append .CreateField("Date", dbText)
.Fields.Append .CreateField("Time", dbMemo)
End With
dbsexist.TableDefs.Append tdfnew 'Make
the new table part of things
Else
End If
Set rstProgramEntry = dbsNew.OpenRecordset("NewTable") 'It was
already here, so we do this...
rstProgramEntry.MoveLast
rstProgramEntry.MoveFirst
rstProgramEntry.Edit
Hope this helps..
Quote:
>Greetings everyone,
>I am trying to delete an old table and replace it with a new one
>(through code) in MS-Access. For deleting the table I am able to use the
>DeleteObject action in a macro. But in order to replace it with a new
>table, I try to use Mydatabase.OpenRecordset("NewTableName"). The help
>files suggest that OpenRecordset will create a new table, but there is
>an error message at run time that NewTableName does not exist. How to
>create a new table??
>Thanks in advance,
>Ashant...
>--
>Ashant Chalasani
>http://expert.cc.purdue.edu/~ashant/
>Ph:765-495-8236