Access 2016 VBA Connect to another Access Table

I using the code below to connect to another access table and get the following error:
AccessOn line - Set CurrentDatabase = DBEngine.Workspaces(0)


Dim CurrentDatabase As Database
Dim MyTableDef As TableDefs
Set CurrentDatabase = DBEngine.Workspaces(0)
OpenDatabase ("U:\Serial Claims DB\Serial_Claims.accdb")
Set MyTableDef = CurrentDatabase.CreateTableDef("tblGlobal")
shieldscoAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dale FyeOwner, Developing Solutions LLCCommented:
which line is it generating the error on?  What is highlighted when you select Debug in the error dialog?
0
Dale FyeOwner, Developing Solutions LLCCommented:
Try modifying your declarations:

Dim CurrentDatabase As DAO.Database
Dim MyTableDef As DAO.TableDef
0
shieldscoAuthor Commented:
Still get an error on line Set CurrentDatabase = DBEngine.Workspaces(0)
0
Powerful Yet Easy-to-Use Network Monitoring

Identify excessive bandwidth utilization or unexpected application traffic with SolarWinds Bandwidth Analyzer Pack.

Dale FyeOwner, Developing Solutions LLCCommented:
should read:

Set CurrentDatabase = DBEngine.Workspaces(0).OpenDatabase ("U:\Serial Claims DB\Serial_Claims.accdb")

all one line
0
shieldscoAuthor Commented:
the code ran without error but did not link the table
0
shieldscoAuthor Commented:
Here is the code

Dim CurrentDatabase As DAO.Database
Dim MyTableDef As DAO.TableDef

Set CurrentDatabase = DBEngine.Workspaces(0).OpenDatabase("U:\Serial Claims DB\SC Address.accdb")
Set MyTableDef = CurrentDatabase.CreateTableDef("tblGlobal")

Open in new window

0
Dale FyeOwner, Developing Solutions LLCCommented:
You don't have any code in what you posted that would:
1. do anything more than create the table on the remote database.  do you have any code that actually creates fields in that table?
2. link the table to the current database, only create the table in the BE.

In order to link that new table in the BE database into your FE, you would need to do something like the following:
set db = CurrentDb
tdf = db.CreateTableDef("tblGlobal")
tdf.Connect = ";DATABASE=U:\Serial Claims DB\Serial_Claims.accdb"
tdf.SourceTableName = "tblGlobal"
CurrentDb.TableDefs.Append tdf

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
shieldscoAuthor Commented:
I get an invalid use of property on line

tdf = Db.CreateTableDef("tblGlobal")

Dim Db As DAO.Database
Dim tdf As DAO.TableDef

Set Db = CurrentDb
tdf = Db.CreateTableDef("tblGlobal")
tdf.Connect = ";DATABASE=U:\Serial Claims DB\SC Address.accdb"
tdf.SourceTableName = "tblGlobal"
CurrentDb.TableDefs.Append tdf

Open in new window

0
Dale FyeOwner, Developing Solutions LLCCommented:
sorry,

Set tdf = db.createtabledef("tblGlobal")
0
Dale FyeOwner, Developing Solutions LLCCommented:
Whenever you work with objects, you must use SET
0
shieldscoAuthor Commented:
Thanks
0
Dale FyeOwner, Developing Solutions LLCCommented:
glad to help
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Databases

From novice to tech pro — start learning today.