Hi,
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
Else
x = "[MachineManufacturerID]="
& tbManufacturer.Text
End If
End If
query = "SELECT IdentMaster.IdentNo, ArtMachineManufacturer.Mac
hineManufa
cturerID , ArtMachineType.MachineType
ID" _
& " FROM IdentMaster, ArtMachineManufacturer" _
& " where " & x & " order by IdentMaster.IdentNo" _
& " WITH OWNERACCESS OPTION"
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
rst.MoveLast
intCount = rst.RecordCount
rst.MoveFirst
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
.AddNew
!IdentNo = rst!IdentNo
!MachineManufacturerID = rst!MachineManufacturerID
!MachineTypeID = rst!MachineTypeID
!GroupID = rst!GroupID
!product = rst!product
!Dimension = FindDimension(rst!IdentNo)
!ToolApplicationID = rst!ToolApplicationID
.Update
End With
End If
rst.MoveNext
Loop
'rst1.Update
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.MoveFirst
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
rst.Close
Set rst = Nothing
End Function
Thank you.
Beginner.
Start Free Trial