"Object no longer valid" Error Message

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mthorpe

    #1

    "Object no longer valid" Error Message

    I am pretty new to all of this and am working on a macro to transfer some data. I am using "Select Case" and when it reaches .Paramater.Appe nd prm(i) is throws the "Invalid Object error". I don't even know where to start trouble shooting this? I'm a novice and need some help. Thanks!

    Code:
    If Len(sSQL) > 0 Then
            Set cmd = New ADODB.Command
            With cmd
                .ActiveConnection = con
                .CommandText = sSQL
                .CommandType = adCmdStoredProc
                For i = 0 To 39
                    If aryData(i) = "" Then aryData(i) = Null
                     Select Case i
                            Case 0 To 2
                                  Set prm(i) = .CreateParameter("@" & aryNames(i), adInteger, adParamInput, , aryData(i))
                            Case 3 To 14
                                  Set prm(i) = .CreateParameter("@" & aryNames(i), adCurrency, adParamInput, , aryData(i))
                            Case 15 To 23
                                  Set prm(i) = .CreateParameter("@" & aryNames(i), adDecimal, adParamInput, , aryData(i))
                                   prm(i).Precision = 18
                                   prm(i).NumericScale = 4
                            Case 24 To 33
                                  Set prm(1) = .CreateParameter("@" & aryNames(i), adBoolean, adParamInput, 0, aryData(i))
                            Case 34 To 34
                                  Set prm(i) = .CreateParameter("@" & aryNames(i), adVarChar, adParamInput, 100, aryData(i))
                            Case 35 To 38
                                  Set prm(i) = .CreateParameter("@" & aryNames(i), adDecimal, adParamInput, , aryData(i))
                                   prm(i).Precision = 18
                                   prm(i).NumericScale = 4
                            Case 39 To 39
                                  Set prm(i) = .CreateParameter("@" & aryNames(i), adCurrency, adParamInput, , aryData(i))
                                  
                     End Select
                     
                     'OBJECT IS NO LONGER VALID ERROR???
    
                    .Parameters.Append prm(i)
                 
    
                Next
    
                .Execute
            End With
            Set cmd = Nothing
        End If
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    What is prm?
    I don't see it defined in the code that you have posted.

    Comment

    Working...