PC Review


Reply
Thread Tools Rate Thread

changing angeslinked table path when table owner in source table ch

 
 
rusl3@optonline.net
Guest
Posts: n/a
 
      12th Nov 2003
I have an access database attached via odbc to a sql 2000
database. We have created about 100 ustom reports in
access but recently during an upgrade to the database, the
table owner was changed and can not be restored but all of
the tables remained the same. All of our linked tables no
longer link properly. I tried the linked table manger but
it didn't work.

Is there any way to change this without having to recreate
all of these reports????
 
Reply With Quote
 
 
 
 
Joe Fallon
Guest
Posts: n/a
 
      16th Nov 2003
You need to re-create the linked tables.
I use code to do this.
When the Owner is DBO the linked table is prefixed with dbo_
My code strips this off so you are left with just the table name.
If your original links had this then you need to re-create them with dbo_
instead of the new owner name.
If they did not have them then you just strip them off as shown below.

Practice with this code in a Test environment until you understand what it
does and then try editing a copy of it to do what you need it to do.

I use this procedure to re-create links to SQL Server.
(This eliminates the need to re-name all the tables to strip out dbo_ and it
allows you to point to different versions of the same database easily.)
There is a local Access table (tblODBCTables) that contains the table names
I want to link to on the Server.
Note: the source table name needs the dbo. prefix which is in the code. The
linked table name usualy omits this. .

Public Sub LinkSQLServerTables(strDSN As String, strDatabase)
On Error GoTo Err_LinkSQLServerTables

Dim dbs As Database, rs As Recordset, tdfAccess As TableDef
Dim dbsODBC As Database, strConnect As String

If strDSN = "" Then
MsgBox "You must supply a DSN in order to link tables."
Exit Sub
Else
strConnect = "ODBC;DSN=" & strDSN & ";UID=User;PWD=password;DATABASE=" &
strDatabase & ";"
End If

SysCmd acSysCmdSetStatus, "Connecting to SQL Server..."

Call DeleteODBCTableNames

Set dbs = CurrentDb
Set rs = dbs.OpenRecordset("tblODBCTables")
Set dbsODBC = OpenDatabase("", False, False, strConnect)

Do While Not rs.EOF
Set tdfAccess = dbs.CreateTableDef(rs![LinkTablename], dbAttachSavePWD)
tdfAccess.Connect = dbsODBC.Connect
tdfAccess.SourceTableName = dbsODBC.TableDefs("dbo." &
rs![LinkTablename]).Name
dbs.TableDefs.Append tdfAccess
rs.MoveNext
Loop

rs.Close
Set rs = Nothing
Set dbsODBC = Nothing
Set dbs = Nothing

Exit_LinkSQLServerTables:
SysCmd acSysCmdClearStatus
Exit Sub

Err_LinkSQLServerTables:
MsgBox ("Error # " & Str(Err.Number) & " was generated by " & Err.Source
& Chr(13) & Err.Description)
Resume Exit_LinkSQLServerTables

End Sub


'This procedure deletes all linked ODBC table names in an mdb.
Public Sub DeleteODBCTableNames()
On Error GoTo Err_DeleteODBCTableNames

Dim dbs As Database, tdf As TableDef, I As Integer
Set dbs = CurrentDb
For I = dbs.TableDefs.Count - 1 To 0 Step -1
Set tdf = dbs.TableDefs(I)
If (tdf.Attributes And dbAttachedODBC) Then
dbs.TableDefs.Delete (tdf.Name)
End If
Next I

dbs.Close
Set dbs = Nothing

Exit_DeleteODBCTableNames:
Exit Sub

Err_DeleteODBCTableNames:
MsgBox ("Error # " & Str(Err.Number) & " was generated by " & Err.Source
& Chr(13) & Err.Description)
Resume Exit_DeleteODBCTableNames

End Sub

--
Joe Fallon
Access MVP



"(E-Mail Removed)" <(E-Mail Removed)> wrote in message
news:071701c3a8d0$cf045f20$(E-Mail Removed)...
> I have an access database attached via odbc to a sql 2000
> database. We have created about 100 ustom reports in
> access but recently during an upgrade to the database, the
> table owner was changed and can not be restored but all of
> the tables remained the same. All of our linked tables no
> longer link properly. I tried the linked table manger but
> it didn't work.
>
> Is there any way to change this without having to recreate
> all of these reports????



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing Database Name and Owner (but not Table Name)in a TypedDat =?Utf-8?B?bWljaGFlbA==?= Microsoft ADO .NET 0 12th May 2007 02:43 PM
Access query/table changing owner in multi-user database =?Utf-8?B?TmVpbCBNb3JyaXM=?= Microsoft Access Security 2 23rd Oct 2006 10:10 PM
Q: Change pivot table source path? =?Utf-8?B?TWFyaw==?= Microsoft Excel Misc 1 27th Jul 2006 12:40 AM
Changing table owner during upsize to SQL? Randy K Microsoft Access 0 18th May 2004 08:03 PM
Q: Changing table owner Manning Microsoft VB .NET 0 30th Sep 2003 05:21 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:06 PM.