President Camacho
President Camacho

Reputation: 1910

Error 3420: Object invalid or no longer set

I'm having trouble with a odbc connection in excel-vba tool.

Public connString As Connection

    Sub login()
        logout
        Set wrkODBC1 = CreateWorkspace("NewODBC", "admin", "", dbUseODBC)
        Set connString= wrkODBC1.OpenConnection("odbc-database", dbDriverNoPrompt, , "ODBC;uid=user;pwd=passwrd;DSN=odbc-database")
    End Sub

    Sub logout()
        On Error Resume Next
        connString.Close
        wrkODBC1.Close
        On Error GoTo 0
    End Sub

When running this code:

login
txt = "SELECT [col1],[col1] FROM database.[dbo].[table]"
sqlToWorksheet sheet, connString, txt


Sub sqlToWorksheet(sheet, conn, sqlString)
    Set temp = conn.OpenRecordset(sqlString, dbOpenSnapshot)

When conn.OpenRecordset is executed I get the error: Error 3420: Object invalid or no longer set. Anyone knows what wrong? Works with my other odbc connections. The database is a mssqlserver2012.

Upvotes: 0

Views: 710

Answers (1)

President Camacho
President Camacho

Reputation: 1910

I forgot this instantiate wrkODBC1, working now.

Upvotes: 0

Related Questions