linking problem after moving from azure access table to azure sql server

I am moving our database from azure access which is on a Microsoft server which can not be modified using the azure portal to sql on the azure portal.  The end goal is to create pages in azure.  During the rewrite the user need to be able to up date the old system.

I was planning to change the odbc link to the new server information. Which I could get each user to do with instructions. The problem is that this causes an ODBC error. The issue is the SQL server table names are being qualified with dbo. and the access tables was not.  Is there a way to stop the qualification at the odbc level so it is easy to relink the tables.  I tried programmatically trying to create the links in the form open event but I keep getting errors.
Who is Participating?
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.

I'll go sideways:
The Azure link strings had a gotcha in them that was unexpected.
I've forgotten it exactly, but here was my connection string

I'd run through the tabledefs collection and set the string:

linkstring = "ODBC;Description=TI_Azure;DRIVER=SQL Server Native Client 10.0;;
APP=Microsoft Office 2003;

                If TD.Connect <> linkstring Then
                    TD.Connect = linkstring
                End If

The gotcha was the UID, I think
The documentation suggested
would do it but
was actually required.
kw66722Author Commented:
I get a data conversion error.

This is the code I am using

dim td as Object -- when I tried as tableDef got compiler error

Dim stConnect As String
    For Each td In CurrentDb.TableDefs
        If td.Name = stLocalTableName Then
            CurrentDb.TableDefs.Delete stLocalTableName
        End If
' I tried the two below with the qualified id and wo.

            ' stConnect = "ODBC;Description=nycpcDatabase;" & _
                    "DRIVER=SQL Server Native Client 11.0;" & _
                    "SERVER=tcp:" & stServer & ";" & _
                    "DATABASE=" & stDatabase & ";" & _
                    "UID=" & stUsername & ";" & _
                    "PWD=" & stPassword & ";" & _
                    "=True;TrustServerCertificate=False;Connection Timeout=30;"
         stConnect = "ODBC; " & _
                     "DRIVER=SQL Server Native Client 11.0; " & _
                     "SERVER=" & stServer & _
                     "DATABASE=" & stDatabase & "; " & _
                     "UID=" & stUsername & "; " & _
                     "PWD=" & stPassword & "; " & _
 Set td = CurrentDb.CreateTableDef(stLocalTableName, dbAttachSavePWD, stRemoteTableName, stConnect)
    CurrentDb.TableDefs.Append td
It's odd that TableDef threw an error.
But ADO tables are a different monster
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

kw66722Author Commented:
When I tried with DAO qualification got an error. ADODB does not exist in Access 2013.  In tried it anyway and it did not work.
It is very strange for a statement like
Dim TD As TableDef to throw an error.

You are doing something fundamentally different than what I do.
You are dropping the tables and recreating them
I change the .Connect property and then issue .RefreshLink

But I am not really thinking clearly.
TD.Name is read/write

You can recreate all your tables and they'll all come in as dbo_TableName
You can run a loop

    For Each td In CurrentDb.TableDefs
         If td.Name Like "dbo_*"  Then
    = right(,len(
         End If

Just shear the dbo_ off the names.
Problem solved.
kw66722Author Commented:
Dim TD As TableDef  - created a compile error.

This reason I deleted the tables so the old tables were removed otherwise in renaming a number 1 is added to the end of the table name. Stripping the dbo_ would mean manually changing the links and then running the script. I was hoping to avoid manual changes.  Since the table names are different the refresh is not working.
I am afraid you have me thoroughly confused.
I normally do NOT delete/create the tables.
I construct a new connection string, update the appropriate tabledef's .connect property and then issue .refresh.
It's done, all the tables point to the new connection string.
It is the coding equivalent of the actions of the Linked Table Manager

The code you posted shows the tables clearly getting whacked
   For Each td In CurrentDb.TableDefs
         If td.Name = stLocalTableName Then
             CurrentDb.TableDefs.Delete stLocalTableName
         End If

and then recreated
Set td = CurrentDb.CreateTableDef(stLocalTableName, dbAttachSavePWD, stRemoteTableName, stConnect)
     CurrentDb.TableDefs.Append td

When I originally created the tables for SQL Server the were all dbo.tblTableName
In Access, I took off the dbo. part
When I hover the mouse over the table, I see the connection string.
The TABLE part of the string has the SQL Server name dbo.tblTableName
So, my Access table objects do not have the same name as my SQL Server table objects.
It's never been a problem.
So, I don't understand what this Since the table names are different the refresh is not working. means

But your syntax here looks ok
Set td = CurrentDb.CreateTableDef(stLocalTableName, dbAttachSavePWD, stRemoteTableName, stConnect)
From the help
Set tabledef = database.CreateTableDef (name, attributes, source, connect)

The issue is the SQL server table names are being qualified with dbo. and the access tables was not.
Why do you believe this has anything to do with it? In the syntax stLocalTableName is the new objects Access name, and stRemoteTableName is the SQL Server object's name.  Heck you can connect to dbo.tblSerious and call it 'foobar' in Access.  It'll work.

but I keep getting errors.
I get a data conversion error.

So, let's see the errors.
I figured the grief was in the .connect property.
The Azure connect string was a bear to debug
Damn thing was case-sensitive and picky about spaces too.
One of the gotchas was in what you have hidden in stUsername

It ABSOLUTELY had to be
and not

I was hoping to avoid manual changes.
Mine ran from autoexec.
If Application.path was c:\azure, it relinked all the tables to the azure server
If Application.path was c:\local, it relinked everything to the inhouse SQL Server
No use input required.

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
kw66722Author Commented:
Let me clarify.

I have an existing access 2013 application with table linked to an Azure server that has access table.  As an example there is a table called tbl_names.  

I took all the access table and recreated them in azure sql server.  I took a copy of the access app and manually tried to relink the tables. It did not work since the name was qualified with the dbo. The tables were not found. I then removed the old access tables from the access application and then link the sql tables, renamed the tables using a procedure I created to get the names to be the same as the ones the forms are using.

I then tried to duplicate the same process programmatically and ran into problems.  I also tried changing the properties of the odbc connection that was connected to the old access Azure database to point to the new sql database and got an ODBC error.

Thanks for your help to date. I hope my explanation makes the problem clearer.
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
<<It is very strange for a statement like
Dim TD As TableDef to throw an error.>>

 It's the references.   For Access 2013, there should be a reference set for:

Microsoft Office 15.0 Access database engine Object

 and if you check the Object Browser, it still shows up as "DAO" ;)

kw66722Author Commented:
That resolved the compile issues the Object was not in the reference library.
It may very well resolve everything else, too.
Test and let us know!
kw66722Author Commented:
I am in the process of testing had other issues that got in the way. Will complete testing today.
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
Microsoft Access

From novice to tech pro — start learning today.