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

clear unbound "dirty" form

Status
Not open for further replies.

montyb

Technical User
Sep 8, 2000
26
0
0
US
I usually use the following code on a "clear" button to remove data entered on a normal, bound form..

Private Sub cmdClear_Click()
If Me.Dirty Then Me.Undo
End Sub

The problem is I have an unbound form I am trying to do the same thing with and I get the following error when pushing the "clear" button (using the same code).

run-time error 2455...you entered an expression thet has an invalid reference to the property Dirty.

How do I remedy this and/or if I have an update button that populates a table with data I just entered on this unbound form, how do I clear the form for the next set of entries (maybe even show a message box that states the data has been entered to the table)? [sig][/sig]
 
Just add this code to a button called cmdClearForm
Then put "ClearMe" in the Tag property of each control you want to have cleared with the click.

Private Sub cmdClearForm_Click()
Dim ctrl As Control
For Each ctrl In Me.Form 'loop thru form to find fields to clear
If InStr(1, ctrl.Tag, "ClearMe") Then
ctrl = vbNullString
End If
Next ctrl

End Sub

good luck.
[sig]<p>John A. Gilman<br><a href=mailto:gms@uslink.net>gms@uslink.net</a><br>[/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top