Running very Slow

I have a very difficult solution(for me) need your help. I created the following code for my application. it run as wht i want but the problem is the process is very slow. it takes more than 10 seconds. Could you pls help me to make the code run much faster? here is my codes:

Dim rst As ADODB.Recordset
Dim query As String
Dim query1 As String
Dim x As Variant

x = Null
'Find Ident No
If Len(cbIdentNo) <> 0 Then
    x = "[IdentMaster].[IdentNo]=""" & cbIdentNo & """"
End If
'Find Machine Manufacturer ID
If Not IsNull(cbManufacturer) And cbManufacturer <> Empty Then
    If Not IsNull(x) Then
        x = x & " and " & "[MachineManufacturerID]=" & tbManufacturer.Text
        x = "[MachineManufacturerID]=" & tbManufacturer.Text  
    End If
End If

query = "SELECT IdentMaster.IdentNo, ArtMachineManufacturer.MachineManufacturerID , ArtMachineType.MachineTypeID" _
& " FROM IdentMaster, ArtMachineManufacturer" _
& " where " & x & " order by IdentMaster.IdentNo" _

Set rst = New ADODB.Recordset
rst.CursorType = adOpenStatic
rst.Open query, conn, , , adCmdText

conn.Execute "Delete * from Result"
'retrieve Result field.
Dim rst1 As ADODB.Recordset
Set rst1 = New ADODB.Recordset
rst1.Open "Select * from Result", conn, adOpenKeyset, adLockOptimistic, adCmdText
Dim intCount, i As Integer
    intCount = rst.RecordCount
    Do Until rst.EOF
        Dim rst2 As ADODB.Recordset
        Set rst2 = New ADODB.Recordset
        rst2.Open "select IdentNo from result where identno =""" & rst!IdentNo & """", conn, adOpenKeyset, adLockOptimistic, adCmdText
        If rst2.RecordCount = 0 Then
            With rst1
            !IdentNo = rst!IdentNo
            !MachineManufacturerID = rst!MachineManufacturerID
            !MachineTypeID = rst!MachineTypeID
            !GroupID = rst!GroupID
            !product = rst!product
            !Dimension = FindDimension(rst!IdentNo)
            !ToolApplicationID = rst!ToolApplicationID
            End With
        End If
End If

Function FindDimension(IdentNo) As String
Dim rst As New ADODB.Recordset
Dim connect_string As String
connect_string = Connection()

With rst
    .CursorLocation = adUseServer
    .CursorType = adOpenKeyset
    .Open "IdentMaster", connect_string, adOpenKeyset, adLockOptimistic, adCmdTableDirect
    .Index = "PrimaryKey"
End With
rst.Seek Array(IdentNo)
If Not rst.EOF Then
    Select Case rst!categorytype
        Case "KSN"
        FindDimension = rst!D & "x" & rst!B & "x" & rst!dSmall & " Z=" & rst!Z & " NL/DKN=" & rst!NL & "/" & rst!DKN
    End Select
End If

Set rst = Nothing
End Function

Thank you.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Also u can set indexes for the fields that are most often used in  a search criteria

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
There seems to be a link between the tables IdentMaster and ArtMachineManufacturer missing in the "query" definition (used by rst).
This can slow the query down significantly and may cause a Cartesian.
Try opening rst2 as adOpenForwardOnly instead of adOpenKeyset (you'll need to replace "if rst2.recordcount=0 then" with "if rst2.EOF=False then") and closing it before repeating the loop.
You've defined intCount as a variant, not an integer. Replace "Dim intCount, i As Integer" with "Dim intCount as Integer, i as Integer".
Also, instead of using the movelast/recordcount/movefirst try incrementing intCount each loop. The movelast may take quite a bit of time. This would also allow you to change rst to adOpenForwardOnly, which is the fastest cursor type, as opposed to using adOpenStatic.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.