Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 7th, 2004, 08:35 AM
Registered User
 
Join Date: Jan 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Store a value to a variable until user quits Acces

I want to store a value to a variable entered in a form that is loaded on startup and keep this value on memory unitl the application closes so that another form uses this value.
I used a public declaration on the first form but the value remains only while the form is open.
Do you have any suggestions?

 
Old January 7th, 2004, 08:52 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Well, here are two choices.

You can create a form with a textbox that holds the data in there and keep this form open but hidden so that you can use the variable in other forms.

You can create a global variable and assign it the value and it'll hold the value as long as the database is open. Which form is open doesn't matter.


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
 
Old January 7th, 2004, 09:04 AM
Registered User
 
Join Date: Jan 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by SerranoG
 Well, here are two choices.

You can create a form with a textbox that holds the data in there and keep this form open but hidden so that you can use the variable in other forms.

You can create a global variable and assign it the value and it'll hold the value as long as the database is open. Which form is open doesn't matter.


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
Considering the second choice, where do I have to declare the global variable so that it maintains its value?

 
Old January 7th, 2004, 09:13 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Click the Module tab on your database and create and save a new module. Below the "Option Compare Database" declare your variable, e.g.

   Public strMyVariable As String

Then set the string in one of your forms as needed. If you're assigning a global variable that's a number that's also constant, you can set the number right up front in the new module, e.g.

   Public Const intMyVariable as Integer = 256

Once you declare a variable as constant, you cannot change it in any form.

Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
 
Old January 7th, 2004, 09:40 AM
Registered User
 
Join Date: Jan 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This seems that it doesn't work. As soon as the form that assigns the value to the variable closes the value is set to null.
If I end up using the second choice (with the textbox), how do I make the form hidden?


 
Old January 7th, 2004, 09:47 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

That's odd... it shouldn't. Did you assign the global variable in its own module from the Module tab or did you just open a form and go to the VB code area and put it there? Do the former, not the latter.

To hide a form, you can set it's Me.Visible = False or merely keep the other forms maximized and open over it at all times.





Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
 
Old January 7th, 2004, 09:58 AM
Registered User
 
Join Date: Jan 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, I created a new module. This is all it contains

Option Compare Database
Option Explicit
Public intCurrentUser As Integer


 
Old January 7th, 2004, 10:18 AM
Registered User
 
Join Date: Jan 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Anyway, I solved my problem using the textbox on the hidden form.

I appreciate your help. Thank you for your time, SerranoG.






Similar Threads
Thread Thread Starter Forum Replies Last Post
How to store user name from LoginName control melania BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 November 3rd, 2008 02:28 PM
dropdown menus OnClick Store To session variable, sionsolo42069 ASP.NET 2.0 Professional 1 March 31st, 2006 03:38 PM
How to store ntext or text value to local variable ramk_1978 SQL Server 2000 3 September 14th, 2005 07:59 PM
How to Store Literal Value in Variable/Parameter kwilliams XSLT 5 August 31st, 2005 08:52 AM
How to store single value in variable? sacred21 Classic ASP Basics 1 December 29th, 2004 05:25 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.