I need to run a update of records from Access to SQL server, and this code appears to work:
Function LinkSQLRS() Dim tdf As DAO.TableDef Const CONSQLSVR = "ODBC;Driver=SQL SERVER;SERVER=YourServerName;UID=YourUserID;PWD=YourPassword;Database=YourSQLDatabase;" Set tdf = CurrentDb.CreateTableDef("tmpLocalTableName") tdf.Connect = CONSQLSVR tdf.SourceTableName = "SQLTableName" CurrentDb.TableDefs.Append tdf 'Do You SQL Here 'Using the Local ODBC Table Name 'etc etc........ 'Kill the temporary linked SQL ODBC Table CurrentDb.TableDefs.Delete ("tmpLocalTableName") End Function
However, when I do this:
strSQL = "SELECT * INTO FROM ;" DoCmd.RunSQL strSQL
the table that was displaying as Linked gets converted to a local table. Doing it the other way (insert into local Access table from linked SQL Server table) doesn’t do that. I have a PK/not null column specified in the linked table in SQL Server.
i suppose there’s something about SELECT INTO that is causing this to happen, will research, but thought I’d put this out there for any comments, etc.
Thanks!