sql >> Base de Datos >  >> RDS >> Sqlserver

MS Access VBA atrapando el error de conexión de SQL Server

El error no ocurrirá hasta que intente agregar TableDef

Dim myDB As DAO.Database
Dim myTabledef As DAO.TableDef

On Error GoTo Err_handler

Set myDB = CurrentDb
scn = "odbc;driver=SqLServer;" & _
"DATABASE=myDB;SERVER=myServer;Trusted_Connection=Yes;"
Set myTabledef = myDB.CreateTableDef("l_table")

myTabledef.Connect = scn
myTabledef.SourceTableName = "Table1"
myDB.TableDefs.Append myTabledef

Err_handler:
Debug.Print Err.Number & " " & Err.Description