create a table (1 Viewer)

dgoulston

Hasn't Got A Clue
Local time
Today, 04:21
Joined
Jun 10, 2002
Messages
403
anyone got a clue whats wrong with this code below?

----------------------------------------------------------------------------
Private Sub Command5_Click()

Dim tablename As String
Dim sourcedb As String
Dim db As Database
Dim tdf As TableDef
Set ws = DBEngine.Workspaces(0)
Set db = CurrentDb()
Set tdf = db.CreateTableDef("DNRACS")
Dim tmpnum As Integer

sourcedb = openfiledb("c:\")
tbTable.Setfocus
tablename = tbTable.text
tmpnum = (InStr(1, sourcedb, "mdb")) + 2
sourcedb = Left$(sourcedb, tmpnum)
'##sourcedb will now contain something like c:\db1.mdb##
'##tablename will containg something like "mytable"##


tdf.Connect = ";DATABASE=" & sourcedb
tdf.SourceTableName = tablename
db.TableDefs.Append tdf

End Sub
--------------------------------------------------------------------------------

any ideas?

thanks in advance

DAL
 

Drevlin

Data Demon
Local time
Today, 04:21
Joined
Jul 16, 2002
Messages
135
Is Openfiledb() a user defined function? And either way, what is it?
 

dgoulston

Hasn't Got A Clue
Local time
Today, 04:21
Joined
Jun 10, 2002
Messages
403
it is what it says, just runs a function that opens a file open diolog and returns the path name.

i think the line of code it is gettin stuck on is:


db.TableDefs.Append tdf

i get the message bout the jet thing cant find the table "mytable"

i gather it is refering to the table from the other database and the table is definetly there.

but i dont know why!!!!
 

Drevlin

Data Demon
Local time
Today, 04:21
Joined
Jul 16, 2002
Messages
135
I've tested your code on A2002 and it seems to be working fine. Of course I didn't create your openfiledb(), just changed the line to:

sourcedb = "c:\My Documents\Testing Database.mdb"

It created a linked table to my "Test" table in the aforementioned database.

Not sure why it wouldn't be working on your end.

Sorry I can't be more help.
 

dgoulston

Hasn't Got A Clue
Local time
Today, 04:21
Joined
Jun 10, 2002
Messages
403
its ok figured this one... i was using the wrong database on me comp, it did contain the table but it was also a linked table...

works fine now.

thanks
 

Users who are viewing this thread

Top Bottom