how direct flow on error? RRS feed

  • Question

  • In my Word macro, I am using ADO to access a SQL Server database and grab data from a table.  It turns out that this table occasionally does not exist, in which case my objRecordset.Open statement below generates an error ("Invalid object name 'xxxxx'")

    Set objConnection = New ADODB.Connection
    objConnection.ConnectionString = "myConnectionString"
    Set objRecordset = New ADODB.Recordset
    objRecordset.ActiveConnection = objConnection
    objRecordset.Source = "SELECT * FROM mytable"

    How can I modify this code so that if I get such an error I can trap it and deal with it later on?  Thanks for any help.

    Tuesday, August 9, 2011 7:45 PM


All replies