Run-time error 91 when executing Stored Procedure in SQL 2012 from MSAccess 2013

  • I am executing an stored procedure in SQL 2012 from MSAccess 2013.

    The Procedure is in command button in a form (see code bellow).

    At Set cmd=cmd.execute a Run-time error 91 (Object variable or With block variable not set) is generated.

    Any suggestions?

    Thanks

    Norbert

    Private Sub cmdBackup_Click()

    Dim cnn As ADODB.Connection

    Dim rst As ADODB.Recordset

    Dim cmd As ADODB.Command

    Dim strConnect As String

    strConnect = "Provider=SQLNCLI11;Server=ISMSERVER2;Database=ISMUTIL;Trusted_Connection=Yes;"

    Set cnn = New ADODB.Connection

    cnn.Open strConnect

    Set cmd = cmd.Execute

    cmd.ActiveConnection = cnn

    cmd.CommandText = "dbo.get_isdmdata_database_backups"

    cmd.CommandType = adCmdStoredProc

    Set rst = cmd.Execute

    Set rst = Nothing

    Set cnn = Nothing

    Set cmd = Nothing

    End Sub

  • Using: Set cmd = cmd.Execute there does not make sense as cmd is declared but not instanciated yet. Use:

    Set cmd = New ADODB.Command

    instead.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply