Textbox looses info when fromis closed

Dcole

New member
Local time
Yesterday, 23:13
Joined
Jul 4, 2024
Messages
7
I have a form the has a few textboxes that get thier info from a combo box. but when i close the form and oprn it back up the textboxes are empty.

is there a was that i can keep the info in the txet box when i open the form and or change records.
 
This is basic behavior of bound forms and bound controls in an Access database. You are getting grief because you don't understand what Access does with forms.

When you tell the form to close, you start a sequence of events including an Unload and a Close event. The text boxes blank out when you unload the form because what is being unloaded IS the set of controls. Which is immediately followed by closing the form. In essence, you were parking data in the form and you took away its parking place with the Unload and then locked the parking lot with the Close..

The text boxes don't necessarily blank out if you merely change records, but it is the nature of the bound controls that if you change records, they WILL change contents. That is what bound forms and controls do. Unbound controls don't lose data across a record change, but they don't automatically GAIN any data either.

You problem is simple to identify but very hard to advise on how to avoid the issue. If you aren't ready to let go of the data, don't close the forum until you have done an acSaveRecord operation. More precisely, a DoCmd.RunCommand acCmdSaveRecord. If the data you wanted to save WASN'T part of a set of bound controls, then you need to save them separately in another table or a temporary location. Don't let go of what you've got on screen until you are done with it.

Opening a form doesn't help you too much because the Form_Open routine (followed by Form_Load and Form_Current) REBUILD the form. The form that you open isn't the form you closed. It is a new reconstruction from scratch of the form from the same design specs. The record that eventually gets posted during the Form_Current processing will usually be the first record of the recordset to which the form is bound.

Can you preserve this? Yes, but it will take some VBA code and some place that will store data in something other than a form. For instance, you can create a Dictionary object and store values in it that would survive a form Close/Open sequence - if the Form_Open or Form_Load sequence included code that got stuff back out of the dictionary. But all that would do is kick the can down the road. If your APP gets closed and then re-opened, the Dictionary doesn't persist across DB close/open events.
 
I have a form the has a few textboxes that get thier info from a combo box. but when i close the form and oprn it back up the textboxes are empty.

is there a was that i can keep the info in the txet box when i open the form and or change records.
How are you filling those textboxes?

I suspect you just need to put that code in the form's current event.
 
I have a form the has a few textboxes that get thier info from a combo box. but when i close the form and oprn it back up the textboxes are empty.

is there a was that i can keep the info in the txet box when i open the form and or change records.
It sounds like the form isn't bound to a record source. Is it?
 
as suggested in post #3 if the comboboxex are Bound and the textbox get their values from the combos, set the textbox values
using the Current Event of the Form, eg:
Code:
Private Form_Current()
Me!Textbox1 = Me!Combo1.Column(1)
End Sub
 
as suggested in post #3 if the comboboxex are Bound and the textbox get their values from the combos, set the textbox values
using the Current Event of the Form, eg:
Code:
Private Form_Current()
Me!Textbox1 = Me!Combo1.Column(1)
End Sub
Thank you this code worked
 
I question the need to save the values in a table. Most of the fields you think you need to save violate normalization rules. Your situation might be unique and require saving copies of values.
 

Users who are viewing this thread

Back
Top Bottom