• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Enable cookies in Userforms

MenofExcel

New Member
SMEs,

Greetings!

I would like to have my userform with cookie supporting functionality. I have added two text boxes and one command button. (file format: .xlax). This file is added to excel ribbon. User would be entering values to any of the text boxes and click on the button. And it will fetch required details from database. Until this part everything works fine. Now, I want to have the recently entered values as cookies in the respective text boxes. Is that possible? If not, is there any possibility to store the last used data??
 
You could use a Project level variable to store the value.
http://www.ozgrid.com/VBA/variable-scope-lifetime.htm

Variables are scoped at different levels, depending on when they are declared. You could store the text box value in them until workbook closes. Also, since you are using a UserForm, you could Hide the UF instead of Unloading, and that would also preserve the value in the text boxes.
 
Is that possible? If not, is there any possibility to store the last used data??

Simply you can book one cell to store last user name, and fetch the name from there.. at user_Form_initialize..

But if you are really looking for..
* Store a key in regedit, and and read the same at startup..
* Different for each System / User .. according to Prefech directory..

Then, you should go for "PED2"..

ProExcelDev.jpg

It has lot of code, for Class Module & Registry Editor..
 
Hi ,

I would advise against using the Registry for such a simple task , where the workbook itself can be used for storing values ; set aside a hidden worksheet or any unused portion of your worksheet as a stack , where the most recently used item is on top.

The advantage of doing this is that you can reuse this construct in any similar situation ; secondly , using the Registry is itself fraught with all the dangers of your Registry getting corrupted if Excel crashes while writing to the Registry !

There are any number of sites which have ready-made code for this :

http://www.codeproject.com/Tips/92203/A-quick-simple-VBA-LIFO-Stack-Implementation-with

http://msdn.microsoft.com/en-us/library/aa227567(v=vs.60).aspx

http://etutorials.org/Microsoft+Pro...A/Recipe+7.2+Create+a+Global+Procedure+Stack/

Narayan
 
Back
Top