473,500 Members | 1,943 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Static Variable problem

35 New Member
Hello,

I am new to this forum and VBA so please bear with me. I have a fairly specific question I think but my terminoligy may be a little messed up.


I want to declare a variable to remain even if access is closed and then re-opened. I thought i could do this by declareing the variable as static, but that doesnt seem to be working. Is there another way?

Thank you for your time and patience
Jan 20 '08 #1
7 2060
lotus18
866 Contributor
Hello,

I am new to this forum and VBA so please bear with me. I have a fairly specific question I think but my terminoligy may be a little messed up.


I want to declare a variable to remain even if access is closed and then re-opened. I thought i could do this by declareing the variable as static, but that doesnt seem to be working. Is there another way?

Thank you for your time and patience
Can you post your code?

Rey Sean
Jan 21 '08 #2
Soulspike
35 New Member
Here it is.


I want to run the following code at start up and force a default if the variables are blank. If they are not blank I leave them alone and use the variables to set the value of some form controls later.


Expand|Select|Wrap|Line Numbers
  1.  
  2. Static DefaultLoc As String
  3. Static DefaultCust As String
  4.  
  5.     If DefaultCust = "" Or DefaultLoc = "" Then 'Check if customer or location if is null
  6.                 DefaultLoc = "SDC"
  7.                 DefaultCust = "Union Pacific Railroad"
  8.  
  9.     End If
  10.  
  11.  
Jan 21 '08 #3
lotus18
866 Contributor
Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim DefaultLoc As String
  3. Dim DefaultCust As String
  4.  
  5.     If DefaultCust = "" Or DefaultLoc = "" Then 'Check if customer or location if is null
  6.                 DefaultLoc = "SDC"
  7.                 DefaultCust = "Union Pacific Railroad"
  8.  
  9.     End If
  10.  
  11.  
Hey

Why don't you try to change your variable declaration to Dim instead of Static? I'm not sure about this, Static is just like a Const (constant).

Rey Sean
Jan 21 '08 #4
Soulspike
35 New Member
Well the problem is that I need the variable to hold its value when I close the application and then open it again. Currently the values go away when I close access. How can I have vb save the values somewhere that I can then retrieve them the next time I open the database?
Jan 21 '08 #5
Killer42
8,435 Recognized Expert Expert
The situation is pretty much the same with most programming languages. Variables are only held in the computer's working memory. Once you exit a program, they're discarded. Generally speaking it doesn't matter what type they are.

If you want them to persist between sessions then you need to store the information somewhere and retrieve it next time your program starts. Typical places to store data between sessions would be...
  • Windows registry
  • A text file
  • A database
There are probably more exotic options (for instance, create a DLL which holds information for you in its address space and returns it when you call it later). But these are the main ones you'll probably want to consider.

Given that you're working in Access, a database table might be the simplest, since you already know the database is there. So why not create a new table, dump your information into it before exiting, and read it back on entry?
Jan 21 '08 #6
Soulspike
35 New Member
Well I was hopeing that I was missing something I am now storing the data in a table and it seems to be working well. Thank you very much for your expertise.
Jan 21 '08 #7
Killer42
8,435 Recognized Expert Expert
Well I was hopeing that I was missing something I am now storing the data in a table and it seems to be working well. Thank you very much for your expertise.
No problem. Glad to see you've got it working.
Jan 21 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

3
28172
by: Marcin Vorbrodt | last post by:
So I have a class Math that looks like this: Math { public: static Real PI(void); }; Real Math::PI(void) { return 4.0 * atan(1.0); }
9
2803
by: AnandRaj | last post by:
Hi guys, I have a few doubts in C. 1. Why static declartions are not allowed inside structs? eg struct a { static int i; }; Throws an error ..
8
6771
by: Simone Chiaretta | last post by:
I've a very strange behaveour related to a website we built: from times to times, something should happen on the server, and all static variables inside the web application, both defined inside aspx...
1
2677
by: Steen Tøttrup | last post by:
This is what I'm doing: I'm using Httpmodules and Httphandlers to control access to files (images, movies, etc.), but have run into quite a problem when several files are being requested at the...
6
1894
by: Vladislav Kosev | last post by:
I have this strange problem now twice: I am writing this relatevely large web site on 2.0 and I made a static class, which I use for url encoding and deconding (for remapping purposes). This static...
55
6149
by: Zytan | last post by:
I see that static is more restricted in C# than in C++. It appears usable only on classes and methods, and data members, but cannot be created within a method itself. Surely this is possible in...
1
3505
by: Sandro Bosio | last post by:
Hello everybody, my first message on this forum. I tried to solve my issue by reading other similar posts, but I didn't succeed. And forgive me if this mail is so long. I'm trying to achieve the...
2
3600
by: HerbD | last post by:
I have a loooong debugging session behind me! I finally found the reason for the problem and now would like to know, if it is a bug in my code or not standardconformant behavour of the compiler(s) or...
3
5827
by: Steve Folly | last post by:
Hi, I had a problem in my code recently which turned out to be the 'the "static initialization order fiasco"' problem (<http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.12>) The FAQ...
11
8290
by: Jef Driesen | last post by:
I have the following problem in a C project (but that also needs to compile with a C++ compiler). I'm using a virtual function table, that looks like this in the header file: typedef struct...
0
7136
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7018
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7182
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7232
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5490
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4923
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3106
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1430
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
672
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.