MS Access VBA trapping SQL Server Connection Error

后端 未结 1 1005
滥情空心
滥情空心 2021-01-27 10:58

I\'m Having problems getting Access (2010) VBA to trap errors for connections to a SQL Server (2008) for linking tables.

I\'m getting an error and popup windows, presuma

相关标签:
1条回答
  • 2021-01-27 11:57

    The error will not occur until you try to append the 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
    
    0 讨论(0)
提交回复
热议问题