
Need help searching for records
I have the following code in a button. I'm trying to speed the
record searching up, does anybody have any suggestions? I have
everybody complaining about how slow Access is. I really think
it is my code. I can do searching by fields so I never got seek
to work right for me.
Private Sub SearchButton_Click()
'do error handling
On Error GoTo SearchErrorHandler
'Make sure NoMatchFlag is false
NoMatchFlag = False
If FindText.Visible = True Then
'Set the Variable for the find item.
FindItem = FindText.Text
'Check & make sure FindItem is not empty.
If FindItem = "" Then
MsgBox "Must Add A Value.", 48, "Search Button"
Exit Sub
End If
Else
FindItem = FindCombo.Text
End If
'Make sure a field has been chosen
If ItemSearchField = "" Then
ItemSearchField = "Problem"
End If
'Set variable for TextOne so we can come back to
'orginal record if no match.
TextOne = Text1.Text
'assign the field for searching
Text1.DataField = ItemSearchField
CLMotData.Refresh
'Move to the first record.
CLMotData.Recordset.MoveFirst
'Run a loop till we hit the search junk
Do Until Text1.Text = FindItem
'Advance the record
CLMotData.Recordset.Update
CLMotData.Recordset.MoveNext
'Check & see if we have hit the End Of File.
CLMotData.Recordset.Update
If CLMotData.Recordset.EOF = True Then
'Do a refresh
CLMotData.Refresh
'Move to the first Record.
CLMotData.Recordset.Update
CLMotData.Recordset.MoveFirst
'Display a message box.
If SearchAddNewFlag = False Then
MsgBox "No match found. Searching for orginial
record.", 48, "Search Button"
Else
'Set the find item to TextOne
FindItem = TextOne
'Assign the textbox datafield
Text1.DataField = "Serial Number"
'Set the nomatchflag
NoMatchFlag = True
'Get out of here.
Exit Sub
End If
'Set the find item to TextOne
FindItem = TextOne
'Assign the textbox datafield
Text1.DataField = "Serial Number"
'Set the nomatchflag
NoMatchFlag = True
End If
Loop
'Reassign text1.datafield to orginal
Text1.DataField = "Serial Number"
'See if there is no match
If NoMatchFlag = True Then
'Exit sub if no match
Exit Sub
End If
'Hide all the find stuff.
FindCombo.Visible = False
FindFrame.Visible = False
FindText.Visible = False
SearchButton.Visible = False
FindItemCombo.Visible = False
'Reset flags
NoMatchFlag = False
'exit sub if no error
Exit Sub
'Do the error handling
SearchErrorHandler:
MsgBox "Error = " & Error$, 16, "SearchButton_Click"
Call CLMotData_Error(Err, 0)
If ExitProgram = True Then
Exit Sub
Else
Resume Next
End If
End Sub