Hi All ,

vb Code:
  1. Do While Not rs.EOF
  2.                              
  3.                              
  4.                                 ReDim Preserve objparameter(0)
  5.                                     With objparameter(0)
  6.                                          .Direction = adParamInput
  7.                                          .Type = adVarChar
  8.                                          .Size = 50
  9.                                          .Value = Me.lblNewRef.Caption
  10.                                     End With
  11.                                 ReDim Preserve objparameter(1)
  12.                                 With objparameter(1)
  13.                                      .Direction = adParamInput
  14.                                      .Type = adVarChar
  15.                                      .Size = 50
  16.                                      .Value = rs.Fields(1)
  17.                                 End With
  18.                                 ReDim Preserve objparameter(2)
  19.                                     With objparameter(2)
  20.                                  
  21.                                          .Direction = adParamInput
  22.                                          .Type = adVarChar
  23.                                          .Size = 100
  24.                                          .Value = rs.Fields(2)
  25.                                     End With
  26.                            
  27.                            
  28.                                 ReDim Preserve objparameter(3)
  29.                                     With objparameter(3)
  30.                                          .Direction = adParamInput
  31.                                          .Type = adVarChar
  32.                                          .Size = 100
  33.                                          .Value = rs.Fields(3)
  34.                                     End With
  35.                                 ReDim Preserve objparameter(4)
  36.                                 With objparameter(4)
  37.                                      .Direction = adParamInput
  38.                                      .Type = adVarChar
  39.                                      .Size = 150
  40.                                      .Value = rs.Fields(4)
  41.                                 End With
  42.                             Set rs_1 = SP_SQL(gdb, "SP_INSERT_ProdDetail", objparameter())
  43.                            
  44.                          
  45.                             rs.MoveNext
  46.                         Loop
  47.  
  48.  
  49.  
  50. Public Function SP_SQL(pstrDBName As String, StorePro As String, ByRef objparameter() As ADODB.Parameter) As ADODB.Recordset
  51. Dim intCountParam As Integer
  52.    Call SQLExecute(pstrDBName)
  53.    
  54.     Set adoCommand = New ADODB.Command
  55.     With adoCommand
  56.         If Not IsEmpty(objparameter()) Then
  57.             For intCountParam = 0 To UBound(objparameter())
  58.                 adoCommand.Parameters.Append objparameter(intCountParam)
  59.             Next
  60.         End If
  61.         .ActiveConnection = conn
  62.         .CommandType = adCmdStoredProc
  63.         .CommandText = StorePro
  64.        
  65.     End With
  66.     Set rs = adoCommand.Execute
  67.        
  68.     Set SP_SQL = rs
  69.    
  70. End Function
  71.  
  72. Public Sub SQLExecute(pstrDBName As String)
  73.     Set conn = New ADODB.Connection
  74.     conn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;" & _
  75.     "Persist Security Info=true;" & _
  76.     "Initial Catalog=Local Mattress System;User Id=;Password=;Data Source=SHLIM\SQLEXPRESS;"
  77.     conn.Open
  78. End Sub

Above is my vb code with public function.

I met a error "Object is no longer valid" on objparameter(adodb.parameter)

I search a lot of source from internal to solve my problem, unfortunately is can't get exactly help. I hope someone of here can help me... thanks