Home Forums Microsoft Access Microsoft Access Access 2003 adp: Run-time error ''91'': Object variable or with block variable not set RE: Access 2003 adp: Run-time error ''''91'''': Object variable or with block variable not set

  • ALTER PROCEDURE dbo.Year_In_@year_In_out_return

    SELECT year=q.year,

    SUM(CASE quarter WHEN 1 THEN amount ELSE 0 END) as Q1,

    SUM(CASE quarter WHEN 2 THEN amount ELSE 0 END) as Q2,

    SUM(CASE quarter WHEN 3 THEN amount ELSE 0 END) as Q3,

    SUM(CASE quarter WHEN 4 THEN amount ELSE 0 END) as Q4

    FROM qtrsales q

    WHERE year = @year

    GROUP BY year

    This will modify the stored proc so that it will return a recordset that

    has fields year,q1,q2,q3,q4

    Now the vb code should look something like this

    Dim cnn as New ADODB.Connection

    Dim cmd as New ADODB.Command

    Dim rst as New ADODB.Recordset

    cnn.Open "Provider=SQLOLEDB;Data Source=;" & _

    "Initial Catalog=adp1SQL;Integrated Security=SSPI;"

    With cmd

    Set .ActiveConnection = cnn

    .CommandType = adCmdStoredProc

    .CommandText = "dbo.Year_In_@year_In_out_return"

    .Parameters.Refresh

    .Parameters("@year") = 1995

    End With

    With rst

    Set .ActiveCommand = cmd

    .Open

    End With

    debug.print rst!year & " " & rst!q1 & " " & rst!q2 & " " & rst!q3 & " " & rst!q4

    rst.close

    cnn.close

    set cmd = nothing

    set rst = nothing

    Set cnn = nothing

    That should be pretty close, I didn't check any of the code but give it a try and I hope it helps.