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

Clearing a form

Status
Not open for further replies.

merlinar

Technical User
Feb 9, 2005
16
US
I would like to know if there is a way that I can have a button clear all the fields in a form so that a user can fill in the blank fields to be used in a search. Any ideas?
 
How are ya merlinar . . . . .

Try this in the [blue]On Click[/blue] event of the button:
Code:
[blue]   Dim ctl As Control
   
   For Each ctl In Me.Controls
      If ctl.ControlType = acTextBox Then
         Me(ctrl.Name) = ""
      End If
   Next[/blue]

Calvin.gif
See Ya! . . . . . .
 
Ok, I put that bit of code in as you said, but now I get an error: "Object Required" If I debug the code, it shows that Me(ctrl.Name) = "" is the line giving the error.

A note, the form is a bound form (I don't know if that makes a difference or not.) But I do need to keep it that way for the search module that I'm using.

Thank you for your help!
 
We have an faq702-5010 written by RoyVidar please check it

Zameer Abdulla
[sub]Jack of Visual Basic Programming, Master in Dining & Sleeping[/sub]
Visit Me
 
Sorry merlinar . . . . Typo . . .

Change Me(ctrl.Name) to Me(ctl.Name) . . .

Calvin.gif
See Ya! . . . . . .
 
ZmrAbdulla: I check out the faq, but it seems to be for unbound forms. Is there maybe a way I can make the form unbound?

TheAceMan1: I changed the line, but I still the the "Cannot assign a value" error.

Is it possible to have Access open a seperate instance of the form without any info in any of the controls?
 
hkaing79:
I'm not sure how I would use that, but I did read the information about it in office help and I don't think it will do what I want.
 
Yes, clearing a form, or clearing form controls, are usually assosiated with unbound forms or unbound controls.

Can't assign a value, which is a different error than object required, can occur for instance while trying to assign a value to a calculated control.

I suspect you're after going to a new record:

[tt]docmd.gotorecord,,acnewrec[/tt]

Roy-Vidar
 
RoyVidar:
I do have some combo boxes, which is probably why it's not working. The new record thing would work, except I have 1 field that is an auto number field and I need to be able to fill that in with a WorkOrder number to look up that record. When I try the new record way, [AutoNumber] appears in the box and I can't edit it. I tried making the form an unbound form, but either #Name appears in all the controls, or I can't use my search module. Is there an easy way to make all the controls unbound and then make them bound again after the search criteria have been entered?
 
I understand what you are trying to accompolish. Please look at the following FAQ702-5106

This will give you a better understanding of the purpose/concept of an autonumber.

You will need to design your own invoice numbering system. The following should give you a method:


HTH

An investment in knowledge always pays the best dividends.
by Benjamin Franklin
Autonumber Description - FAQ702-5106
 
After all these posts I feel you can use an UnboundCombo to lookup your records.
Place a combo on the form and choose the third option from the wizard (Find a record.....)
Choose the AutoNumber field as record finder. You don't have to clear the form to lookup a record or use the search code. You can either choose reocrd form the combo or type into it.
Hope this helps



Zameer Abdulla
[sub]Jack of Visual Basic Programming, Master in Dining & Sleeping[/sub]
Visit Me
 
I have looked through various FAQ in search of a method of clearing 5 fields in a sub-form. I would like to push a button then clear those fields. They are simple fields [Name, Date, a yes/no box, and 2 combo boxes].
Is this too difficult? I do not have much VB experience.
Any help would be appreciated
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top