SpookiePower said:
I have a lot of Textboxes and comboboxes on my form.
I can clear each box in this way -
Me!nameofbox = null
But what can I do if I don't want to write this line for each box I
have on my form ?
If you are working with a bound form, clearing this way, would remove
the contents of the current record. If it is alredy saved, you will
probably get some errors due to trying to alter the primary key to
Null, same with controls bound to required fields etc.
So, for bound forms, I'd perhaps be more inclined to try to undo
unsaved changes, alternatively, run a delete query to delete the
current record (air code).
if me.newrecord then
Me.Undo
else
currentdb.execute "delete from mytable where PK = " & _
me!txtPK, dbfailonerror
end if
Or, just go to a new record with something like
DoCmd.GotoRecord , , acNewRec
If you're working with an unbound form, then you could probably loop
the controls collection (air code)
dim ctl as control
for each ctl in me.controls
select case ctl.controltype
case actextbox, accombobox ' other relevant control types
ctl.value = Null
end select
next ctl
set ctl = nothing
You would propably need some errorhandling, and perhaps also exclude
some controls from the handling