Clearing out controls

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm not totally familiar with all the things you can do in VBA in Access. I
created a form in Access 2000. The user enters data and clicks a button and
the table is updated. No biggie. But, after the table is updated, I wanted
to clear the screen and leave it fresh for another entry. I know how to do
that with something like this:

Dim i As Integer


For i = 0 To Me.Count - 1
If TypeOf Me(i) Is TextBox Then
Me(i) = ""
End If
Next

But that leads me to a problem in that some of the text fields are dates and
some of them are integers and if they are not filled in properly, an error
occurs because a blank cannot be put in a date field.

What I was wondering is, how do I set the form back to the way it was when
the form originally opened? At that point, I could enter data in just one
field and then click update and it was accepted. I guess the fields are null
when the form first opens? I'm not sure how that works. I know I could go
back and do all the checking for blanks, but there are 116 fields and I'm
just feeling lazy. :) Is there some function or anything in Access that
will allow a form to be reset to exactly the way it was when originally
opened?

Thanks,
Jennifer
 
You could use the following instead:


SendKeys "{ESC}{ESC}"

That will set the data back to the original values.
 
But, after the table is updated, I wanted
to clear the screen and leave it fresh for another entry.

Set default values on the controls... then you don't have to enter any vba
at all.

If you really want to use vba, you can set each control to its def val:

For i = 0 To Me.Count - 1
If TypeOf Me(i) Is TextBox Then
Me(i).Value = Me.control(i).DefaultValue
End If
Next


Hope that helps


Tim F

PS: _please_ don't use SendKeys...
 
If I read your post correctly, all you want to do is add a new record:

In design view, add a command button to your form. Using the wizard, select
"Record Operations," then "Add New Record"

Or you can use the record selector at the bottom of the form.
 
Is the form linked to a record source (a table or query)? If so, you don't
want to clear the controls on the form unless you are moving to a new
record. Clearing the controls would clear the data in the underlying table.

If the form is unbound, then try setting the controls to NULL vice "" (a
zero-length string).
 
Just add this after the DoCmd for saving.It should do the trick.

DoCmd.GoToRecord , , acNewRec

Regards
Sunil
 
Back
Top