Error CreateTableDef in latest Access version

As a database developper, I've created many Access databases over the last 15 years. In almost every database I created, I use vba to (re)link tables that are located in a SQL Server database. My code looks like this:

First I check if the table already exists. If so, I delete the table:
CurrentDb.TableDefs.Delete strLocalTableName
CurrentDb.TableDefs.Refresh

Next I build a connection string:
ODBC;DRIVER={SQL Server Native Client 11.0};SERVER=XXXXX;DATABASE=XXXXX;UID=dps;PWD=xxxxx

In the final step I try to link the table (again):
Set td = CurrentDb.CreateTableDef(strLocalTableName, dbAttachSavePWD, strRemoteTableName, strConnectionStringNative)
CurrentDb.TableDefs.Append td

All parameters are correct. I double checked them.

After an automatic update of Access on my main computer this code does not seem to work anymore. I get "Error 3001 - Invalid argument".

No matter which Access database I try (different customers), they all fail on this command. My version of Access:
Access 2021 MSO (Version 2212 Build 16.0.15928.20186) 64-bit


The strange thing is that the same code (even using the same Access file) works fine on another computer. The Access version on that computer however is:
Access 2019 MSO (Version 2211 Build 16.0.15831.20098) 64-bit

So it seems that it only occurs with the latest update of Access/Office. Any ideas how to get this working again?

Answer
Answer

I would try something like this:

Set td = CurrentDb.CreateTableDef("TempName", dbAttachSavePWD, strRemoteTableName, strConnectionStringNative)

td.Name = strLocalTableName
CurrentDb.TableDefs.Append td

It is possible that there is still something that it doesn't like about your table name, even if it doesn't have spaces, dashes etc. By giving it "TempName" it should get past the first line. Then you seem to be able to give it whatever name you want (including spaces and special characters) with the td.Name= command.

5 people found this reply helpful

·

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated October 22, 2024 Views 789 Applies to: