I knew I had made this work in the past, so I did some checking. In my
situation I had a series of Search text boxes and combo boxes to set up the
filter. After entering values in several of the Search controls, a command
button ran code to combine the values into a filter string. If no matching
record was found, the controls were reset to their Tag value. More on that
in a a moment.
What I discovered in a test is that I cannot reset a control in its Before
Update event. However, if I execute the code in a command button click event,
or the control's After Update event for that matter, then I can reset the
text box.
Back to the tags, say I have two unbound controls, a combo box and a text box,
with these values entered:
Acme Company
December 2009
I search for records by clicking a Search command button and running code
along the lines of yours. There are some records, so I set the Tag property
of the controls to Acme Company and December 2009 (actually, it would have
been the CompanyID for Acme Company, but the point remains the same).
The next search is for Beta Company, November 2009. There are no records, so
the controls are reset in the command button click event to their Tag values,
so that they show the values of the last successful search.
I know you said the After Update event will not work, but I do not understand
the reasoning. Have you tried running the code in the After Update event,
except without Cancel = True, and with
Me.FullName = ""
instead of
Me.FullName.Undo
if the search returns nothing?
Alternatively, you can reset FullName in the Enter or Got Focus event of next
control (the one to which the focus goes). It seems you can reset it almost
anywhere except the Before Update event. I expect there is a way of doing
this that will work within the context of how the form works.
Bruce,
Using TextBoxName = Me.TextBoxName.Tag doesn't work. I had already tried
setting the value to Null, and got the same error. Using the AfterUpdate
isn't useful becuase the focus goes to the next field. The undo method
highlights the control, so I'll go with that. It allows tabbing to the next
control, keeping the incorrect value, but I have another check on the Add
button. Not the best way to go, but this form will be seldom used.
Thank you and God Bless,
Mark
I think you cannot use Undo for an unbound control. As a workaround you
can
[quoted text clipped - 34 lines]