Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reset form ?

Status
Not open for further replies.

cass60660

Programmer
Nov 13, 2002
30
0
0
US
How to reset a form in Access(VBA)?
I have a form with multiple fields and I want to clrear the form(all the fields). I need something like Reset button in html form.

thanks
 
I think you have to reference each field and reset the value. Something like this :-

Me!Field1.Value = Null

or maybe .....

Me!Field2.Value = ""

or for speed (check all the controls on the form and reset if appropriate).....

For x = 1 To Me.Count - 1
If TypeOf Me(x) Is TextBox Then
Me(x).Value = Null
End If
Next x


Good Luck,
Top Jack.

 
Have all the field names obey a naming convention, perhaps the textboxes all start with "Text", all the listboxes start with "List", etc. For my example I use the first four characters of each name. If you don't want to clear the field, then don't name it according to your naming convention.

Set up a For-Each loop, looping through the controls.

Do something like:
Code:
Dim OfTheControls as Control
For Each OfTheControls In ThisUserForm.controls

Select Case Left(OfTheControls.Name,4)

Case "Text"
         OfTheControls.Text = vbNullString
Case "List"
         OfTheControls.Clear

Case "Chec"
         OfTheControls.Value = False
End Select
Next
 
Can you not just do ...

Me.Undo

... perhaps followed by ...

Me.firstcontrol.SetFocus

Enjoy,
Tony
 
Hi Judge,

Undo can reset a control or a form. Me (in the form's code module) refers to the form and, so, Me.Undo should reset all controls on the form. It will, of course, reset them to what they were before they were changed, not actually initialise them but I assumed a starting point of an empty form; perhaps my assumption was false, cass60660 has never come back to tell us.

Enjoy,
Tony
 
Yes, it was a bit late, but an addiction is an addiction!

Although I sometimes look at the VB Forum, I wouldn't presume to answer questions about VB, as opposed to VBA. I will leave that to the more competent.

Enjoy,
Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top