How do I clear a form without posting data (1 Viewer)

sambo

Registered User.
Local time
Yesterday, 16:58
Joined
Aug 29, 2002
Messages
289
I have a form that allows users to enter data.
What if they begin to enter data and realize that it is all wrong.
How do I create a button the allows them to clear the form data and start again from scratch?
Using the DataEntry = True will post the already entered data as a new record. I don't want to do this, I simply want to clear all the fields and txtboxes on the form.
 

Dave Eyley

Registered User.
Local time
Today, 00:58
Joined
Sep 5, 2002
Messages
254
I do this a lot because it allows you to check the entry before it gets saved to a table.
The way I do this is -
On the form use unbound fields with similar names to the table fieldnames.
Beside each field create a button marked 'CLEAR' and in its 'On Click' property use code to write - [Fieldname]=Null
where [Fieldname] is the name of the adjacent field.

When all the input is in you need a bit of code to save all the data to the table, and this is where it can get tricky.
This is the code I use which is started from a button called 'Save'

Dim MyDb As Database
Dim MySet As Recordset
Set MyDb=DBEngine.Workspaces(0).Databases(0)
Set MySet=MyDb.OpenRecordset ("TableName")

MySet.AddNew
MySet![Field1]=Me!Field1
MySet![Field2]=Me!Field2
MySet![Field3]=Me!Field3
.....as many fields as you want to save......
MySet.Update

MySet.Close
MyDb.Close

I know it looks a bit complicated....but use it as written and just change the tablename and fieldnames to suit.
You could add another button at the bottom of the screen to Clear all the fields in one go by just using the 'On Click' property and, as above, enter -
Field1=Null
Field2=Null
Field3=Null
.....and on and on for all the fields on the form...

Good Luck.

Dave Eyley
 

sambo

Registered User.
Local time
Yesterday, 16:58
Joined
Aug 29, 2002
Messages
289
I like the looks of this idea. It looks kind of brutish at first glance, but I will try it.
Thanks
 

sambo

Registered User.
Local time
Yesterday, 16:58
Joined
Aug 29, 2002
Messages
289
This is a great idea. I am getting through this and realizing how many of my problems are going to go bye bye just by using this method. I was having problems with Null values stored in primary and index holders, those are no more since now my fields are not bound to fields on the table.
Correct me if I am wrong, but can't I scrap the recordsource of my form altogether now? Since I am controlling exactly what goes where when the user clicks the button?
If so, that would be great.
 

Dave Eyley

Registered User.
Local time
Today, 00:58
Joined
Sep 5, 2002
Messages
254
There is no need for a record source on forms where there are no bound fields. I'm glad it worked for you. There's something masochistically enjoyable about Access!
When the light dawns and the solution comes......WHAO!

Cheers

Dave E
 

JJordan

Registered User.
Local time
Yesterday, 18:58
Joined
Jul 25, 2002
Messages
53
And doesn't the Command Button wizard get you the same place by setting the button to record operatins, undo ? CLears the whole form for me.
 

Users who are viewing this thread

Top Bottom