How do you change the fields on a form to their default values ?

  • Thread starter Thread starter Excalibur
  • Start date Start date
E

Excalibur

Hello :)

I like a button on a form where people can click on to reset all fields to
their default values.
I am new to Access and couldn't find any simple command to do so.
So maybe this needs some coding instead ?

Thanx in advance.

Rob Hofkens.
 
Hi,
do you want to to reset all fields to their default values, before your record is saved or after your record is saved.

If it is before you saved the record than you can try these:
1. Click on menu EDIT, UNDO.
or
2. Create a command button and follow the 'command button' wizard that follow. Select from Categories: Record Operations and Action: Undo record.

Hope this help.

----- Excalibur wrote: -----

Hello :)

I like a button on a form where people can click on to reset all fields to
their default values.
I am new to Access and couldn't find any simple command to do so.
So maybe this needs some coding instead ?

Thanx in advance.

Rob Hofkens.
 
Thanx Trias but your answer is not that what I seek.
The Undo option resets values to their previous (pre edit) value.

When designing a table one can change the default value of a tables field.
A new record will always show the fields with their default value.
Users can changes the values though and save the record.

I would like the user to be able to go back to a certain record and press a
button which resets the fields back to the default value.

Its like when you install a game and it comes up with a lot of default
settings which every user can change according to their PC.
Like screen resolution, sound settings etc.
In most cases the game offers a button to reset all values back again to
default settings.

Hope this makes it better to understand what I mean.

Thx.

Trias said:
Hi,
do you want to to reset all fields to their default values, before your
record is saved or after your record is saved.
If it is before you saved the record than you can try these:
1. Click on menu EDIT, UNDO.
or
2. Create a command button and follow the 'command button' wizard that
follow. Select from Categories: Record Operations and Action: Undo record.
 
Thanx Trias you hit the jackpot this time :)
You helped me a lot with this code!
Looks like I have to go a long way before understanding Access.

Cheers.

Trias said:
Hi Excalibur,

so you want a user to be able to go to certain record in a table, and by
pushing a button, change all value in that record to whatever the default
value is set for each column on the table?. Here is my simplified solution.
Suppose you have a command button called cmdReset on your Form, here is what
the code looks like on the OnClick event of that button:
Private Sub CmdReset_Click()
Dim db As DAO.Database, tbl As DAO.TableDef, fld As DAO.Field, rst As DAO.Recordset

'get Form recordset
Set rst = Me.Recordset

Set db = CurrentDb
'assuming your Form Recorsource is a table, called MyTbl
set tbl = db.tabledef!MyTbl

With rst
.Edit
For Each fld In tbl.Fields
'replace the value in the selected record with Default Value of Fields
.Fields(fld.Name) = fld.DefaultValue
Next
.Update
End With

'Cleanup
Set fld = Nothing
Set tbl = Nothing
Set rst = Nothing
Set db = Nothing
end sub

Be aware that i didn't put any means to trap error that can occure. Also,
you might find it helpfull if you look at Access Help file for DAO,
TableDefs, Fields.
 
Back
Top