FIND in array speed problem

User avatar
sal21
PlatinumLounger
Posts: 4355
Joined: 26 Apr 2010, 17:36

FIND in array speed problem

Post by sal21 »

I use this for next to find in array ...

Code: Select all

For T = 0 To UBound(strDBRows3, 2)
                If Me.Text8.Text = strDBRows3(0, T) Then
                    NOME_MATR = " " & strDBRows3(1, T)
                    Me.LAB_MATR.Caption = NOME_MATR
                    Exit For
                End If
            Next T
but is very slow :groan: :sad:
is possible to find in "one shot only" instead?

User avatar
HansV
Administrator
Posts: 78489
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: FIND in array speed problem

Post by HansV »

The array represents the records in a recordset, yes?
If so, why don't you look up the value in the table/query?

Code: Select all

    strSQL = "SELECT Field1, Field2 FROM ... WHERE Field1=" & Me.Text8.Text
    RS.Open strSQL, ...
    If Not RS.EOF Then
        NOME_MATR = " " & RS.Fields("Field2")
    End If
    ...
The above assumes that 'Field1' is a number field. If it is a text field, use

Code: Select all

    strSQL = "SELECT Field1, Field2 FROM ... WHERE Field1=" & Chr(34) & Me.Text8.Text & Chr(34)
Best wishes,
Hans