I have created a search box and clear/reset button using the codes below in access 2007. When I search for a data and clear the fields and attempt to search thesame field again, it returns no search and when I check the data table, the record is deleted. Is there a way to fix this?
Thanks.
CLEAR FIELDS CODE
Private Sub clearfields_Click()
me.textfields.value = "" ------------- (I repeated this for the different textfields)
End Sub
SEARCH CODE
Private Sub cmdSearch_Enter()
Dim WINSRef As String
Dim strSearch As String
'Check txtSearch for Null value or Nill Entry first.
If IsNull(Me![txtSearch]) Or (Me![txtSearch]) = "" Then
MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criterion!"
Me![txtSearch].SetFocus
txtSearch.SetFocus
txtSearch = ""
Exit Sub
End If
'----------------------------------------------------------------------------
'Performs the search using value entered into txtSearch
'and evaluates this against values in strWINS
DoCmd.ShowAllRecords
DoCmd.GoToControl ("WINS")
DoCmd.FindRecord Me!txtSearch
WINS.SetFocus
WINSRef = WINS.Text
txtSearch.SetFocus
strSearch = txtSearch.Text
'If matching record found sets focus in strSearch and shows msgbox
'and clears search control
If WINSRef = strSearch Then
MsgBox "Match Found For: " & strSearch, , "Congratulations!"
txtSearch.SetFocus
txtSearch = ""
'If value not found sets focus back to txtSearch and shows msgbox
Else
MsgBox "Match Not Found For: " & strSearch & " - Please Try Again.", _
, "Invalid Search Criterion!"
txtSearch.SetFocus
End If
End Sub
Thanks.
CLEAR FIELDS CODE
Private Sub clearfields_Click()
me.textfields.value = "" ------------- (I repeated this for the different textfields)
End Sub
SEARCH CODE
Private Sub cmdSearch_Enter()
Dim WINSRef As String
Dim strSearch As String
'Check txtSearch for Null value or Nill Entry first.
If IsNull(Me![txtSearch]) Or (Me![txtSearch]) = "" Then
MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criterion!"
Me![txtSearch].SetFocus
txtSearch.SetFocus
txtSearch = ""
Exit Sub
End If
'----------------------------------------------------------------------------
'Performs the search using value entered into txtSearch
'and evaluates this against values in strWINS
DoCmd.ShowAllRecords
DoCmd.GoToControl ("WINS")
DoCmd.FindRecord Me!txtSearch
WINS.SetFocus
WINSRef = WINS.Text
txtSearch.SetFocus
strSearch = txtSearch.Text
'If matching record found sets focus in strSearch and shows msgbox
'and clears search control
If WINSRef = strSearch Then
MsgBox "Match Found For: " & strSearch, , "Congratulations!"
txtSearch.SetFocus
txtSearch = ""
'If value not found sets focus back to txtSearch and shows msgbox
Else
MsgBox "Match Not Found For: " & strSearch & " - Please Try Again.", _
, "Invalid Search Criterion!"
txtSearch.SetFocus
End If
End Sub