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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Easy way to clear a form? 4

Status
Not open for further replies.

anasazii

Programmer
Jun 19, 2001
59
US
I have an unbound form with multiple text boxes. I have placed a button on the form, with the purpose of using it to clear the form... Just curious if there is a simple way to do this other then setting all of the text values to "", and also to return the boxes to their default setting (ie visible/disabled, etc).
Thanks for any help...
 
I do it this way. I place all sorts of information in the Tag property regarding the controls corresponding tablename, fieldname, whether the field is required to save the record, etc.... Place in the Tag something like this
ctlText.Tag = "vbNullString;True;False"
This tag, for instance, would tell me that:
it's default setting = ""

it's visible property = True
it's enabled property = False

Now, onto the routine

Private Sub FormatForm()
Dim ctl as Control
dim arrTemp as variant

for each ctl in me.controls
if Typeof ctl is Textbox then
arrtemp = split(ctl.tag, ";")'Creating an array
ctl.value = arrtemp(0)
ctl.Visible = arrtemp(1)
ctl.Enabled = arrtemp(2)
end if
next

end sub

That routine works like a charm for me

You can put this in a standard module and pass the form into the routine so that you do not have to recreate it again and again.

Hope that helps.

Bob


 
I know that you asked this question nearly a year ago, but thought you might like a quick and dirty solution to clearing a form.

Create a macro that uses the SendKeys Action. In the Keystrokes type (Esc); Wait property to No.

Either list the macro as the on Click event for your command button control or use the DoCmd.RunMacro ("mcrSendEsc") in VBA Code.

Best of luck.
sathandle :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top