Saving information in a form  
Author Message
HMariana





PostPosted: Visual Basic for Applications (VBA), Saving information in a form Top

Hope someone can help!

i have created a form in access where the user needs to input some information. What I want to do is be able to save this information on the form so that the next time I open the form the information is displayed, and also have the ability to change any field and save the changes. I also want to be able to save the information in an access table.

Thanks a lot, I really appreciate any feedback/suggestions.

HMariana



Microsoft ISV Community Center Forums2  
 
 
nobugz





PostPosted: Visual Basic for Applications (VBA), Saving information in a form Top

Moved to VBA forum.


 
 
Derek Smyth





PostPosted: Visual Basic for Applications (VBA), Saving information in a form Top

Hi,

I wrote a blog entry about how to do this

http://dsmyth.blogspot.com/2006/05/saving-user-interface-state.html

Generally what you want to do is create a class that contains all the data entered/displayed on the form. Add two properties to the form, one property that gets the forms data and returns an instance of the class, the other property takes an instance of the class and uses it to populate the controls on the form.

If you do this you can hold the data in the form (the forms state) seperately from the form. So when the form closes the class can still be held in memory, or saved and read to a file, or even used by another form.

You can write methods inside the state class that saves (persist) the data to any data store, file, excel, access. If you write the method in the class then every instance of the class knows how to persist itself. i.e. MyFormState.SaveToAccess() or MyFormState.SaveToFile(), or even through the form as in MyForm.State.SaveToFile() - state here is the forms property that gets an instance of the state class, the forms data in one class.

This works very well I've used it in a number of applications.



 
 
HMariana





PostPosted: Visual Basic for Applications (VBA), Saving information in a form Top

Thanks for your response, it was very helpful :)