Object variable not set (Error 91)

496 Views Asked by At

I have a problem ADODB.RECORDSET, i have MSFlexGrid called flgFact what is filled with data and i want to add that data related on a recordset called rsDetal but when i compile the code it drop me (error 91 : Object variable or With block variable rate is not) in the if

Private Sub cmdeport_Click()
    Dim rsDetal As ADODB.Recordset
    Set rsDetal = flgFact.DataSource
    If Not (rsDetal.EOF And rsDetal.BOF) Then
           rsDetal.MoveFirst
           Do While Not rsDetal.EOF
           Numdocu = rsDetal(4)
           Fec_Emision = rsDetal(5)
           Totl = rsDetal(16)
           Igve = rsDetal(17)
           Totv = rsDetal(18)
           Mont_Pade = rsDetal(14)
           Mont_Paco = rsDetal(15)
           Call TEMPTRAMA(Numdocu, Fec_Em, Totl, Igve, Totv, Mont_Pade, Mont_Paco)
           rsDetal.MoveNext
           Loop
    End If
End Sub

i checked my value rsDetal and the value taken from the MSFlexGrid is Nothing

1

There are 1 best solutions below

0
Marc On

If your MSFlexGrid isn't bound to a DataSource then .DataSource will be Nothing.

You need to iterate through the rows of the grid and access the text in each column. Just a change to the way you are looping, and you may need to cast the string values from the grid to the correct types.

Dim lngRowCount As Long, lngFixedRowCount As Long, lngRowIndex As Long

lngRowCount = MSFlexGrid1.Rows
lngFixedRowCount = MSFlexGrid1.FixedRows

For lngRowIndex = lngFixedRowCount To lngRowCount - 1
    'Access values using MSFlexGrid1.TextMatrix(lngRowIndex, 0), where 0 is the column
Next lngRowIndex