Connecting Tech Pros Worldwide Help | Site Map

linking tables to different databases

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 13th, 2005, 02:04 PM
jomonto@zeus.kern.org
Guest
 
Posts: n/a
Default linking tables to different databases

Hello-

Here is my situation. I have multiple copies of the same database on
our MS SQL server (same program, but differnet funding streams). I have
an Access 2003 front end that I link to the SQL server for ad-hoc
reports and queries. I link all the tables I need from a database (for
instance: dbo.tProvider, dbo.tParents, etc) Then I rename the tables
links in Access to just tParents, tProvider... this way I can have one
query, one report - I just update the links to the new database
whenever I need to change sources. Is there a clever way of renaming
the 'linked' table names in Access - to remove the dbo. (Im using a
painful macro right now)?

....and I have a new problem. So far this has worked out great. Because
all the databases are the same and the table ownership has been dbo.
But we recently added another copy, but the tables are
NewDBA.tProvider, NewDBA.tParent, etc (diff ownership for reason beyond
this message). So now insted of just updating the links - i have to
delete the links and create new ones - then rename to the simple form
(tProvider).

Any suggestions??

thanks,
john-


  #2  
Old November 13th, 2005, 02:04 PM
Douglas J. Steele
Guest
 
Posts: n/a
Default Re: linking tables to different databases

For the first problem, you can use the following code:

Dim dbCurr As DAO.Database
Dim tdfCurr As DAO.TableDef

Set dbCurr = CurrentDb()
For Each tdfCurr In dbCurr.TableDefs
If StrComp(Left$(tdfCurr.Name, 4), "dbo_", 1) = 0 Then
tdfCurr.Name = Mid$(tdfCurr.Name, 5)
End If
Next tdfCurr

Set dbCurr = Nothing

I'm assuming that the tables are actually like dbo_tProvider, not
dbo.tProvider

For the second, you could write a loop to delete the tables if that makes it
any easier:

Dim dbCurr As DAO.Database
Dim tdfCurr As DAO.TableDef
Dim intLoop As Integer

Set dbCurr = CurrentDb()
For intLoop = (dbCurr.TableDefs.Count - 1) To 0 Step -1
Set tdfCurr = dbCurr.TableDefs(intLoop)
If Len(tdfCurr.Connect) > 0 Then
dbCurr.TableDefs.Delete tdfCurr.Name
End If
Next intLoop

Set dbCurr = Nothing

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)



<jomonto@zeus.kern.org> wrote in message
news:1128377925.363963.265280@g47g2000cwa.googlegr oups.com...[color=blue]
> Hello-
>
> Here is my situation. I have multiple copies of the same database on
> our MS SQL server (same program, but differnet funding streams). I have
> an Access 2003 front end that I link to the SQL server for ad-hoc
> reports and queries. I link all the tables I need from a database (for
> instance: dbo.tProvider, dbo.tParents, etc) Then I rename the tables
> links in Access to just tParents, tProvider... this way I can have one
> query, one report - I just update the links to the new database
> whenever I need to change sources. Is there a clever way of renaming
> the 'linked' table names in Access - to remove the dbo. (Im using a
> painful macro right now)?
>
> ...and I have a new problem. So far this has worked out great. Because
> all the databases are the same and the table ownership has been dbo.
> But we recently added another copy, but the tables are
> NewDBA.tProvider, NewDBA.tParent, etc (diff ownership for reason beyond
> this message). So now insted of just updating the links - i have to
> delete the links and create new ones - then rename to the simple form
> (tProvider).
>
> Any suggestions??
>
> thanks,
> john-
>[/color]


  #3  
Old November 13th, 2005, 02:04 PM
jomonto@zeus.kern.org
Guest
 
Posts: n/a
Default Re: linking tables to different databases

Wow - this worked perfect.
I guess I have a ton of reading to do, really need to study up on
TableDefs.
Thank you for the starting place.

john-

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.