Clear Buttom Deleting data from record

cegbuna

New Member
Joined
Mar 26, 2011
Messages
37
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
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

Forum statistics

Threads
1,224,608
Messages
6,179,872
Members
452,949
Latest member
Dupuhini

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top