I would like to have a command buttom on my form and on click clear all entries. Please help with the code?
I would like to have a command buttom on my form and on click clear all entries. Please help with the code?
Is your form bound to a Recordset and are all of the controls bound as well?
It is bound to a table/guery as well as controls bound to the same.
Are you just tryine to get to a *new* blank record or are you trying to wipe out and existing record? You do understand the if you are on an existing record and clear a bound control, that is also trying to clear the field in the recordset as well right?
Did I lose you there?
No I'm not lost but in and out today. Sorry for the delay geting back.
I looking to have the command button just clear the info I just typed in and did not save and still have the form stay open.
Me.UnDo will return all controls on the form back to what is saved in the Recordset.
Thank You.
I am now working with a MS template and the code I found is as follows:
Private Sub cmdCancel_Click()
' User wants to bail
' If an edit in progress..
If (Me.Dirty = True) Then
' Clear it
Me.Undo
End If
' And close me
DoCmd.Close acForm, Me.Name
End Sub
I think I have a simple question:
How can I stop the form from closing but still clear data I just inputed so I can enter new data?
You lost me on that one. How about just don't Close the form? That's too easy right?
I agree. I don't want to close the form.
The code I have from the template closes the form. I am not familiar with code and was asking how to modify this code or write new code to clear the opened form and not close it so I can start new data input with cleared form.
Just comment out the second to last line:
DoCmd.Close acForm, Me.Name
...just add a ' at the beginning of the line like:
' DoCmd.Close acForm, Me.Name
Simple, thanks for the info change. I thought I did that a couple of days ago. I guess I deleted something wrong.
When I got the code to work I noticed it truely does UnDo the data inputted but data in a past saved record will not be cleared. Is there another command to clear the data and update that record? Or is this not recommended?
That is usually done by deleting the record and starting with a new one.
Are you ready to call this thread Solved? It is one of the Thread Tools.
We are done and I thank you for your help.