"Creating a TableDef object is supposed to create a table, so what you're
describing doesn't really make sense."
Now I don't feel so bad, it doewn't make sense to me, either.
Code looks like
If Dir("C:\Cobra conversion\DataCheck.mdb") <> "" Then
'MsgBox "Datacheck Exists"
Kill "C:\Cobra Conversion\DataCheck.mdb"
End If
Set appAccess = CreateObject("Access.Application")
appAccess.Visible = True
With appAccess
..NewCurrentDatabase ("C:\Cobra Conversion\DataCheck.mdb")
..Visible = True
End With
Set dbs = appAccess.CurrentDb
' ----------Create a new TableDef object.
Set tdfResources = dbs.CreateTableDef("Resources")
'------------Populate the TableDef with names for each range in the
Spreadsheet
'------------Pick up the names Fromt he Workbook Names collection
For r = 1 To ActiveWorkbook.Names.Count
'MsgBox (ActiveWorkbook.Names(r).Name)
Rangename = ActiveWorkbook.Names(r).Name
'------------Then , using the TableDef Created above:
With tdfResources
'--------- Create fields and append them to the new TableDef
'--------- object. This must be done before appending the
'--------- TableDef object to the TableDefs collection of the database
.Fields.Append .CreateField(""" & Rangename & """, dbText)
'--------Finish with this loop through the TableDef
End With
'--------Pick up the next Rangename to add to the tabledef
Next r
'-----------End of looping through rangename and TableDef
'---------- Append the new TableDef object to the database.
dbs.TableDefs.Append tdfResources
----------------------------------------------------------------------------------
All of this apparently works, at least it doesn't throw any errors, but the
database does not show any tables appended, yet.
On the other hand, this did work In which case I don't need the tabledef:
Set dbs = OpenDatabase("C:/Cobra Conversion/datacheck")
dbs.Execute "CREATE TABLE Resources (ResourceID, Period, WBS, Hours,
Units )"
dbs.OpenTable ("Resources")
appAccess.RefreshDatabaseWindow
But now seems to be broken (sigh) This won't meet my needs since I need to
loop through and pick up the rangenames as above.
"Douglas J. Steele" wrote:
> You say you've got code that "creates a database and creates a TableDef".
> What does the code look like? Creating a TableDef object is supposed to
> create a table, so what you're describing doesn't really make sense.
>
> --
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
> (no e-mails, please!)
>
>
> "Hydra" <(E-Mail Removed)> wrote in message
> news:9B3F8289-9F3D-428F-9227-(E-Mail Removed)...
> > Another example"
> >
> > "You can use DAO objects, such as the Database, TableDef, Recordset, and
> > QueryDef objects, to represent objects that are used to organize and
> > manipulate data, such as tables and queries, in code."
> >
> > OK, Swell, glad to know that.
> >
> > So I have a TableDef that represents a table, which organizes my data. How
> > do I convert the table def into an actual table? (OK actual is
> > meaningless
> > since both the Tabledef and the table are just digital constructs.) Why
> > would
> > I want to use an object to represent another object? Why not use the table
> > object and manipulate data there?
> >
> >
> >
> >
> >
> > "fredg" wrote:
> >
> >> On Mon, 29 Jun 2009 07:22:01 -0700, Hydra wrote:
> >>
> >> > OK, I've got code that creates a database and creates a TableDef, but I
> >> > cannot figure out how to turn the Tabledef into a table that I can
> >> > populate.
> >> > I've got code that shows how to populate an existing table from and
> >> > Excel
> >> > file, but Ineed to fisrt creat the table.
> >> >
> >> > Heve not found anything in help, or object browser, or external text,
> >> > yet
> >> > this would seemto be a pretty basic operation.
> >> >
> >> > What's worse it that I know I have done it before........
> >>
> >> I assume there is a reason to do this programmatically, rather than
> >> just clicking New from the Database Table Objects window.
> >>
> >> Any reason why you haven't used the Help files already on your
> >> computer?
> >>
> >> Help + Contents + Microsoft Access Help + Microsoft Data Access
> >> Objects 3.60 + Microsoft DAO 3.60 + DAO Methods Reference + C +
> >> CreateTableDef Method.
> >>
> >> Or......
> >>
> >> from the Help Contents menu navigate to:
> >>
> >> Microsoft Jet SQL Reference + Data Definition Language + Create Table
> >> Statement
> >>
> >> Both methods include examples.
> >>
> >> --
> >> Fred
> >> Please respond only to this newsgroup.
> >> I do not reply to personal e-mail
> >>
>
>
>
-----------------------------------------------------------------------------
Our Peering Groups change
Visit :
http://spacesst.com/peerin