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!

Clearing Field Values in a form

Status
Not open for further replies.

scollins

MIS
Nov 30, 2001
5
0
0
US
Is there anyway to clear all field values in a form in one statement?

thank you -
 
Hi!

There is function which clears all controls on form.
Create commandbutton on your form (e.g. <cmdClear>) Copy following code in procedure On Click:

private cmdClear_OnClick()
call UpdateToNull(me)
end sub

Sub UpdateToNull(frm As Form, _
Optional blnOnlyUbound As Boolean = True, _
Optional blnIncludeSubForms As Boolean = False)
'This recursive function updates all form's
'textboxes and comboboxes to Null value.
'If parameter <blnIncludeSubForms> is set True then
'all textboxes and comboboxes of all subforms will update
'If parameter <blnOnlyUbound> is set false then
'all all textboxes and comboboxes will update
'otherwise only unbound controls will update.

Dim ctl As Control

On Error Resume Next
For Each ctl In frm.Controls
Select Case ctl.Properties(&quot;ControlType&quot;)
Case acTextBox, acComboBox
If ctl.Properties(&quot;ControlSource&quot;) <> &quot;&quot; Then
If Not blnOnlyUbound Then
GoTo NextControl
End If
End If
ctl = Null
Case acSubform
If blnIncludeSubForms Then
Call UpdateToNull(frm, blnIncludeSubForms)
End If
End Select
NextControl:
Next ctl
End Sub


Try it!
You may sub program UpdateToNull() copy into any module.

Aivars |-0

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top