When I execute this code it takes about a 30 seconds to execute. The first part of the code goes through about 1500 records looking to see if NSN and command match.
Is there a better way to do a two factor search or filter?
Is there a better way to do a two factor search or filter?
Code:
Private Sub ChangeNSN_Click()
Dim selectedCommand As String
Dim NSN, NOMENCLATURE, PartNumber As String
Dim rst As ADODB.Recordset
Dim strCriteria As String
Dim Command As String
Command = GetCmd()
Set rst = New ADODB.Recordset
With rst
.Open "AuthorizedUserList", CurrentProject.Connection, adOpenKeyset, adLockOptimistic
.MoveFirst
Do While Not .EOF
If IsFound(.Fields("NSN"), Command) = True Then 'IF Record is selected
.Fields("selected") = -1
Else
.Fields("selected") = 0
End If
.MoveNext
Loop
End With
rst.close
Set rst = Nothing
DoCmd.close
DoCmd.OpenForm "frmChooseQuickList"
End Sub
Function IsFound(NSN As String, Command As String) As Boolean
Dim Db As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
IsFound = False
strSQL = "SELECT * FROM QuickNSN Where NSN = '" & NSN & "' AND COMMAND = '" & Command & "'"
Set Db = CurrentDb()
Set rst = Db.OpenRecordset(strSQL, dbOpenDynaset)
With rst
If .EOF Then
IsFound = False
Else
IsFound = True
End If
End With
rst.close
Set rst = Nothing
End Function