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

Clear fields in a form

Status
Not open for further replies.

dmoran

Technical User
Feb 12, 2004
13
US
I know that this has been a subject here before, but I could not find a solution applicable to me - I have a DB where 1 person enters records. I then have users on a network who are linked to the table. The form gets its record from a single combo box entry - easy enough. Because the "user" needs only to lookup a street name in the combo box and view the record, I have a button called "search" that requeries the form and "clears/resets" the combo box(txtcombobox=null). To minimize confusion, I would also like to "clear" the form fields before the new street is selected. I don't need a new record because the user will not be editing/adding anything. I'm fairly new at this and have limited VB skills but am willing to try any suggestions. Thanks in advance - David
 
Code:
Dim ctl As Control
For Each ctl in Me
   If ctl.ControlType = acTextBox Then
      ctl.Value = ""
   EndIf
Next ctl

 
Just popping in - are you sure you really want to clear all controls vs goto new record?

Reason I ask is that if this is a form bound to a table/query, then clearing all controls this way will delete all values for the current record.

Another thing, if any of the text controls on the form has a calculated controlsource, then it'll bomb, "can't assign a value to this object".

This can be avoided with adding a little test:

[tt]if left$(ctl.controlsource,1)<>&quot;=&quot; then
'... and proceed[/tt]

Last issue, if the primary key is an Autonumber, you'll get the same error there too (probably some ambiguities with other datatype PK's too). There I don't know any other workaround than to clear by deleting the whole record.

Roy-Vidar
 
Thanks Roy - I think that will be the solution. I thought about the AddNewRecord option but thought it might keep adding blank records every time a user searched for a record - but thats not the case since there will be no data added. Thanks for the help. David
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top