Clearing Forms

J

Justin

Have a question, i have this order entry form, where the user enter
appropriate data and once press "Add record", it will first check a table
that will see if that data that was just enter is duplicated to what the
table has. If it does, it will open up another form, showing the user the
data. Now i need to have it that it has a yes and no button,

yes, to add this data
and no to delete teh data, and return to other screen

My problem when creating the NO button, i created to go back to other form,
but the information is still there.

Need help.thanks
 
A

Arvin Meyer [MVP]

The default behavior of Access is to use bound forms. The data will then be
saved automatically. You can use unbound forms and write code to explictly
save the record, or you can use the bound form, save the record, and then
delete it. The second method is actually much simpler. Some sample code to do
it might look like this:

Sub NoSave_Click()
DoCmd.RunCommand acCmdSaveRecord
CurrentDb.Execute "Delete * From MyTable Where IDField=" & Me.txtIDField
End Sub

Of course you need to substitute the appropriate names.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads
http://www.datastrat.com
http://www.mvps.org/access
 
J

Justin

Im getting an error when i made the appropriate changes

this is what i did

CurrentDb.Execute "DELETE Check_Data_OrderEntry.*,
Check_Data_OrderEntry.KeyNumber FROM Check_Data_OrderEntry WHERE
(Check_Data_OrderEntry.KeyNumber)" = Me.txtKeyNumber

but im getting the error "compile error, method or data not found.

please help
 
D

Douglas J Steele

Your equal sign is in the wrong place, and you're missing the concatentation
operator. (As well, there's no need to include KeyNumber specifically in the
DELETE part: the query deletes the entire row, not specific fields):

CurrentDb.Execute "DELETE * FROM Check_Data_OrderEntry " & _
"WHERE KeyNumber = " & Me.txtKeyNumber

That assumes that KeyNumber is a numeric field. If it's text, you'll need to
use

CurrentDb.Execute "DELETE * FROM Check_Data_OrderEntry " & _
"WHERE KeyNumber = " & Chr$(34) & Me.txtKeyNumber & Chr$(34)

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)
 
Top