How to clear a textbox contents when moving from one record to another (1 Viewer)

sbrown106

Member
Local time
Today, 17:47
Joined
Feb 6, 2021
Messages
77
Hi,

Could somebody help me with this please. I have a form that contains hundreds of records, and the user moves from one record to the next checking/inputting data.
I have a Dmax lookup function in the form that calculates a max value for a field when the user makes a selection from a combo box.
The idea being if the value provided to the text box from the lookup function is above a certain value a msgbox will appear to warn the user.
This all works well but then when I go to the next record the value is still in the text box. I know clearing the text box can be done manually with a button, however there is a lot of data on the form and it can be easy to miss. Is there a way to clear a textbox when the user leaves the form, the textboxes in question are unbound

The form is within a NavForm

so Navform-->Form1(accessed on menutab on navform)-->form2 ( accessed by a button from form1)
The 2 textboxes I need to clear on are in form2 (txtbox1,txtbox2)

Is there a simple way to do this when the user moves from one record to the next within form2 design. Sorry if ive not explained that very well.
Its probably simple but been going round in circles with buttons and trying form onload events but they only seem to work when the form is loaded, where as
I want to clear the text boxes when moving between the records in the form. Thanks for any help
 

Gasman

Enthusiastic Amateur
Local time
Today, 17:47
Joined
Sep 21, 2011
Messages
14,217
Yes, the OnLoad name gives a clue, executed once when the form loads. :)

To do what you ask, in the Current event of the form
Code:
Me.txtbox1 = ""
Me.Txtbox2 = ""
or use Null
Might want to also give better names. Hopefully these textboxes are unbound, else you will remove data.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 12:47
Joined
Feb 19, 2002
Messages
43,201
Unless the user needs to see the value in the textbox, you don't need the value to be on the form at all. It can be a variable in the program that is displayed in the messagebox.
 

sbrown106

Member
Local time
Today, 17:47
Joined
Feb 6, 2021
Messages
77
Yes, the OnLoad name gives a clue, executed once when the form loads. :)

To do what you ask, in the Current event of the form
Code:
Me.txtbox1 = ""
Me.Txtbox2 = ""
or use Null
Might want to also give better names. Hopefully these textboxes are unbound, else you will remove data.
I tried that-I loaded the form but then the text box values didn’t change when I moved to the next record
Yes, the OnLoad name gives a clue, executed once when the form loads. :)

To do what you ask, in the Current event of the form
Code:
Me.txtbox1 = ""
Me.Txtbox2 = ""
or use Null
Might want to also give better names. Hopefully these textboxes are unbound, else you will remove data.
Thanks GasMan - works now!
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 12:47
Joined
Feb 19, 2002
Messages
43,201
text box values didn’t change when I moved to the next record
That's the way unbound textboxes work. Each row of a continuous form is an instance of the same form and the form can have only one set of properties.

As I said, do not display the value unless the user has to see it for some reason
 

Users who are viewing this thread

Top Bottom