How can I get "CONSTANT" behavior from a variable (Constant magic)?

running access 2k;
And before anything else is said - "Yes, Virginia, I know you can NOT
use a variable to set a constant (that's why it's constant)".

BUT - my problem is - I want a constant, that I can set from a
variable (one time)!!!

When my application starts, the user is prompted to make a selection
from a list.
I want that selection to go into a global variable, and NEVER CHANGE
while the application is running. This means that if the application
encounters an unexpected error - this value is NOT lost.

If the user wants to change this value, they should have to close the
application and restart.

This is the BEHAVIOR I'm looking for.....

Is this behavior possible, and if so, how?

BTW -
I should mention, that I successfully accomplished this by actually
programatically inserting a global constant statement into a "globals
module" ! (the insertion statement, of course used a variable to
define the statement). Problem is, (no surprise), this can NOT be done
in a run-time application.... ;o)

thoughts or discussion?

TIA!!
Bob
0
bobg
2/4/2008 10:25:47 PM
access.formscoding 7493 articles. 0 followers. Follow

19 Replies
918 Views

Similar Articles

[PageSpeed] 46

Perhaps if you explain a bit more about this value, how it is created and 
how it is going to be used, someone might be able to help.

Jeanette Cunningham

<bobg.hahc@gmail.com> wrote in message 
news:e5b8d001-c52b-4167-b666-a4921e11b9b9@m34g2000hsb.googlegroups.com...
> running access 2k;
> And before anything else is said - "Yes, Virginia, I know you can NOT
> use a variable to set a constant (that's why it's constant)".
>
> BUT - my problem is - I want a constant, that I can set from a
> variable (one time)!!!
>
> When my application starts, the user is prompted to make a selection
> from a list.
> I want that selection to go into a global variable, and NEVER CHANGE
> while the application is running. This means that if the application
> encounters an unexpected error - this value is NOT lost.
>
> If the user wants to change this value, they should have to close the
> application and restart.
>
> This is the BEHAVIOR I'm looking for.....
>
> Is this behavior possible, and if so, how?
>
> BTW -
> I should mention, that I successfully accomplished this by actually
> programatically inserting a global constant statement into a "globals
> module" ! (the insertion statement, of course used a variable to
> define the statement). Problem is, (no surprise), this can NOT be done
> in a run-time application.... ;o)
>
> thoughts or discussion?
>
> TIA!!
> Bob 


0
Jeanette
2/4/2008 10:55:13 PM
The only thing that comes to mind would be to have a utility table that you
write this value to when your app opens, then either refer to it directly
each time you need it, or, if you are a good do-bee and have error handling
routines on all procedures, re-assign it to a global variable if an error is
encountered.

I use such a table for holding things like company addresses, phones numbers,
fax numbers, etc, that are used in printouts. That way, if any of these
things change, the end user can change the information, which wouldn't be
possible if it
were hardwired. You can also use it to store information about the last
record that was worked on, so that the user can pick up where they left off.

-- 
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via http://www.accessmonster.com

0
Linq
2/4/2008 11:41:38 PM
bobg.hahc@gmail.com wrote:

>running access 2k;
>And before anything else is said - "Yes, Virginia, I know you can NOT
>use a variable to set a constant (that's why it's constant)".
>
>BUT - my problem is - I want a constant, that I can set from a
>variable (one time)!!!
>
>When my application starts, the user is prompted to make a selection
>from a list.
>I want that selection to go into a global variable, and NEVER CHANGE
>while the application is running. This means that if the application
>encounters an unexpected error - this value is NOT lost.
>
>If the user wants to change this value, they should have to close the
>application and restart.
>
>This is the BEHAVIOR I'm looking for.....
>
>Is this behavior possible, and if so, how?
>
>BTW -
>I should mention, that I successfully accomplished this by actually
>programatically inserting a global constant statement into a "globals
>module" ! (the insertion statement, of course used a variable to
>define the statement). Problem is, (no surprise), this can NOT be done
>in a run-time application.... ;o)


Putting the value in a text box on an always open, hidden
form is much safer then a global variable.

A one row (one field?) table is the natural choice in a
database system.

-- 
Marsh
MVP [MS Access]
0
Marshall
2/5/2008 12:54:05 AM
"Marshall Barton" <marshbarton@wowway.com> wrote in message 
news:rlcfq3945lfvjo80fqtlet8ui7docq0rof@4ax.com...
> bobg.hahc@gmail.com wrote:
>

> A one row (one field?) table is the natural choice in a
> database system.

  or a dozen lines in a Class module...

> -- 
> Marsh
> MVP [MS Access] 


0
MikeB
2/5/2008 1:47:16 AM
hi Jeanette;
TX for your reply...

Basically, I have 2 separate [to the user] applications. Each uses the
same tables, and nearly the same forms / user interface.

I don't want the user confused about which application he/she's in, so
I want them to choose 1, and live with it as long as it's open. So I
have an autoexec that asks which app they want, and I would like that
answer to be my "application constant"...

Marshall's solution sounds like a good one, but I was curious if you
had another....

TX...
Bob


On Feb 4, 4:55 pm, "Jeanette Cunningham"
<n...@discussions.microsoft.com> wrote:
> Perhaps if you explain a bit more about this value, how it is created and
> how it is going to be used, someone might be able to help.
>
> Jeanette Cunningham
>
> <bobg.h...@gmail.com> wrote in message
>
> news:e5b8d001-c52b-4167-b666-a4921e11b9b9@m34g2000hsb.googlegroups.com...
>
> > running access 2k;
> > And before anything else is said - "Yes, Virginia, I know you can NOT
> > use a variable to set aconstant(that's why it'sconstant)".
>
> > BUT - my problem is - I want aconstant, that I can set from a
> > variable (one time)!!!
>
> > When my application starts, the user is prompted to make a selection
> > from a list.
> > I want that selection to go into a global variable, and NEVER CHANGE
> > while the application is running. This means that if the application
> > encounters an unexpected error - this value is NOT lost.
>
> > If the user wants to change this value, they should have to close the
> > application and restart.
>
> > This is the BEHAVIOR I'm looking for.....
>
> > Is this behavior possible, and if so, how?
>
> > BTW -
> > I should mention, that I successfully accomplished this by actually
> > programatically inserting a globalconstantstatement into a "globals
> > module" ! (the insertion statement, of course used a variable to
> > define the statement). Problem is, (no surprise), this can NOT be done
> > in a run-time application.... ;o)
>
> > thoughts or discussion?
>
> > TIA!!
> > Bob

0
bobg
2/5/2008 7:52:58 PM
hi Marshall;

TX, this sounds like a very workable solution, and I definitely like
it better than a global variable... I'll give it a try...

TX
Bob

On Feb 4, 6:54 pm, Marshall Barton <marshbar...@wowway.com> wrote:
> bobg.h...@gmail.com wrote:
> >running access 2k;
> >And before anything else is said - "Yes, Virginia, I know you can NOT
> >use a variable to set aconstant(that's why it'sconstant)".
>
> >BUT - my problem is - I want aconstant, that I can set from a
> >variable (one time)!!!
>
> >When my application starts, the user is prompted to make a selection
> >from a list.
> >I want that selection to go into a global variable, and NEVER CHANGE
> >while the application is running. This means that if the application
> >encounters an unexpected error - this value is NOT lost.
>
> >If the user wants to change this value, they should have to close the
> >application and restart.
>
> >This is the BEHAVIOR I'm looking for.....
>
> >Is this behavior possible, and if so, how?
>
> >BTW -
> >I should mention, that I successfully accomplished this by actually
> >programatically inserting a globalconstantstatement into a "globals
> >module" ! (the insertion statement, of course used a variable to
> >define the statement). Problem is, (no surprise), this can NOT be done
> >in a run-time application.... ;o)
>
> Putting the value in a text box on an always open, hidden
> form is much safer then a global variable.
>
> A one row (one field?) table is the natural choice in a
> database system.
>
> --
> Marsh
> MVP [MS Access]

0
bobg
2/5/2008 7:55:28 PM
Linq:

I appreciate your reply...

I should have mentioned that I did think of storing it in a table...
I just shy away from doing this, because of performance... there's
dlookup; which is Really bad (performance-wise).
I could always do a sql call, but prefer to just grab it out of memory
if at all possible....

Of course, this would have been a fall-back position, saving any other
ideas....

TX again!
Bob

On Feb 4, 5:41 pm, "Linq Adams via AccessMonster.com" <u28780@uwe>
wrote:
> The only thing that comes to mind would be to have a utility table that you
> write this value to when your app opens, then either refer to it directly
> each time you need it, or, if you are a good do-bee and have error handling
> routines on all procedures, re-assign it to a global variable if an error is
> encountered.
>
> I use such a table for holding things like company addresses, phones numbers,
> fax numbers, etc, that are used in printouts. That way, if any of these
> things change, the end user can change the information, which wouldn't be
> possible if it
> were hardwired. You can also use it to store information about the last
> record that was worked on, so that the user can pick up where they left off.
>
> --
> There's ALWAYS more than one way to skin a cat!
>
> Answers/posts based on Access 2000/2003
>
> Message posted viahttp://www.accessmonster.com

0
bobg
2/5/2008 7:59:58 PM
On Feb 4, 7:47 pm, "MikeB" <m.byerleyATVerizonDottieNettie> wrote:
> "Marshall Barton" <marshbar...@wowway.com> wrote in message
>
> news:rlcfq3945lfvjo80fqtlet8ui7docq0rof@4ax.com...
>
> > bobg.h...@gmail.com wrote:
>
> > A one row (one field?) table is the natural choice in a
> > database system.
>
>   or a dozen lines in a Class module...
>

Hmm....
Mike - interesting idea; although, admittedly, I haven't done much
with classes...
You don't have to spell out every letter, but could you give me an
idea of how this would work?

TX IA!
Bob
0
bobg
2/5/2008 8:03:03 PM
Marsh's solution is easy to implement. You can do a similar thing with 
creating a settings table in the front end to store the value and do a 
DLookup each time you want to retrieve the value. There is a third way of 
using Properties - but it is more advanced stuff to wrap your head around.

Jeanette Cunningham

<bobg.hahc@gmail.com> wrote in message 
news:7855ca11-52ae-4118-8ac6-c214b3461b35@j78g2000hsd.googlegroups.com...
> hi Jeanette;
> TX for your reply...
>
> Basically, I have 2 separate [to the user] applications. Each uses the
> same tables, and nearly the same forms / user interface.
>
> I don't want the user confused about which application he/she's in, so
> I want them to choose 1, and live with it as long as it's open. So I
> have an autoexec that asks which app they want, and I would like that
> answer to be my "application constant"...
>
> Marshall's solution sounds like a good one, but I was curious if you
> had another....
>
> TX...
> Bob
>
>
> On Feb 4, 4:55 pm, "Jeanette Cunningham"
> <n...@discussions.microsoft.com> wrote:
>> Perhaps if you explain a bit more about this value, how it is created and
>> how it is going to be used, someone might be able to help.
>>
>> Jeanette Cunningham
>>
>> <bobg.h...@gmail.com> wrote in message
>>
>> news:e5b8d001-c52b-4167-b666-a4921e11b9b9@m34g2000hsb.googlegroups.com...
>>
>> > running access 2k;
>> > And before anything else is said - "Yes, Virginia, I know you can NOT
>> > use a variable to set aconstant(that's why it'sconstant)".
>>
>> > BUT - my problem is - I want aconstant, that I can set from a
>> > variable (one time)!!!
>>
>> > When my application starts, the user is prompted to make a selection
>> > from a list.
>> > I want that selection to go into a global variable, and NEVER CHANGE
>> > while the application is running. This means that if the application
>> > encounters an unexpected error - this value is NOT lost.
>>
>> > If the user wants to change this value, they should have to close the
>> > application and restart.
>>
>> > This is the BEHAVIOR I'm looking for.....
>>
>> > Is this behavior possible, and if so, how?
>>
>> > BTW -
>> > I should mention, that I successfully accomplished this by actually
>> > programatically inserting a globalconstantstatement into a "globals
>> > module" ! (the insertion statement, of course used a variable to
>> > define the statement). Problem is, (no surprise), this can NOT be done
>> > in a run-time application.... ;o)
>>
>> > thoughts or discussion?
>>
>> > TIA!!
>> > Bob
> 


0
Jeanette
2/5/2008 8:04:12 PM
If the table is in the front end, the performance issue is a non-issue, the 
user is only fetching the data from a table stored on their own desktop - 
nothing needs to be fetched from linked tables across the network.

Jeanette Cunningham

<bobg.hahc@gmail.com> wrote in message 
news:54c2f1a7-68e1-41bb-9db9-0e972000c818@f10g2000hsf.googlegroups.com...
> Linq:
>
> I appreciate your reply...
>
> I should have mentioned that I did think of storing it in a table...
> I just shy away from doing this, because of performance... there's
> dlookup; which is Really bad (performance-wise).
> I could always do a sql call, but prefer to just grab it out of memory
> if at all possible....
>
> Of course, this would have been a fall-back position, saving any other
> ideas....
>
> TX again!
> Bob
>
> On Feb 4, 5:41 pm, "Linq Adams via AccessMonster.com" <u28780@uwe>
> wrote:
>> The only thing that comes to mind would be to have a utility table that 
>> you
>> write this value to when your app opens, then either refer to it directly
>> each time you need it, or, if you are a good do-bee and have error 
>> handling
>> routines on all procedures, re-assign it to a global variable if an error 
>> is
>> encountered.
>>
>> I use such a table for holding things like company addresses, phones 
>> numbers,
>> fax numbers, etc, that are used in printouts. That way, if any of these
>> things change, the end user can change the information, which wouldn't be
>> possible if it
>> were hardwired. You can also use it to store information about the last
>> record that was worked on, so that the user can pick up where they left 
>> off.
>>
>> --
>> There's ALWAYS more than one way to skin a cat!
>>
>> Answers/posts based on Access 2000/2003
>>
>> Message posted viahttp://www.accessmonster.com
> 


0
Jeanette
2/5/2008 8:18:26 PM
AHH....
a lookup table in the front-end.... yea, performance should be much
less an issue with that, but I still think dlookup is costly....

But; I'll keep that in mind; in situations that may be the best
solution....

And, actually, I hadn't thought to use properties... I already use
them for app version reporting, and such...
Not hard to use at all.... and probably "cheaper" than a dlookup even
to a local table.....


TX!

On Feb 5, 2:18 pm, "Jeanette Cunningham"
<n...@discussions.microsoft.com> wrote:
> If the table is in the front end, the performance issue is a non-issue, the
> user is only fetching the data from a table stored on their own desktop -
> nothing needs to be fetched from linked tables across the network.
>
> Jeanette Cunningham
>
> <bobg.h...@gmail.com> wrote in message
>
> news:54c2f1a7-68e1-41bb-9db9-0e972000c818@f10g2000hsf.googlegroups.com...
>
> > Linq:
>
> > I appreciate your reply...
>
> > I should have mentioned that I did think of storing it in a table...
> > I just shy away from doing this, because of performance... there's
> > dlookup; which is Really bad (performance-wise).
> > I could always do a sql call, but prefer to just grab it out of memory
> > if at all possible....
>
> > Of course, this would have been a fall-back position, saving any other
> > ideas....
>
> > TX again!
> > Bob
>
> > On Feb 4, 5:41 pm, "Linq Adams via AccessMonster.com" <u28780@uwe>
> > wrote:
> >> The only thing that comes to mind would be to have a utility table that
> >> you
> >> write this value to when your app opens, then either refer to it directly
> >> each time you need it, or, if you are a good do-bee and have error
> >> handling
> >> routines on all procedures, re-assign it to a global variable if an error
> >> is
> >> encountered.
>
> >> I use such a table for holding things like company addresses, phones
> >> numbers,
> >> fax numbers, etc, that are used in printouts. That way, if any of these
> >> things change, the end user can change the information, which wouldn't be
> >> possible if it
> >> were hardwired. You can also use it to store information about the last
> >> record that was worked on, so that the user can pick up where they left
> >> off.
>
> >> --
> >> There's ALWAYS more than one way to skin a cat!
>
> >> Answers/posts based on Access 2000/2003
>
> >> Message posted viahttp://www.accessmonster.com

0
bobg
2/5/2008 8:40:57 PM
Here is a more detailed link:

http://support.microsoft.com/kb/209968

Here is a simple example:

Add a Class Module to your project called clsMyProp


Add the following Code to the module:
+++++++++++++++++++++++++++++++
Option Compare Database
Option Explicit

Private mvMyClassVar As String

Private Sub Class_Initialize()
  'if you wanted a Default Startup Value
  'You would set it here:
  'mvMyClassVar = "Initialized"
End Sub

Public Property Let MyClassValueToStore(s As String)
   mvMyClassVar = s
End Property

Public Property Get MyClassValueToStore() As String
   MyClassValueToStore = mvMyClassVar
End Property

Private Sub Class_Terminate()
   'Any Cleanup Code for the Class you Would do Here
   'MsgBox "Class Terminated", vbInformation, "Class Example"
End Sub

+++++++++++++++++++++++++++++++

Add the following Code to a Form module or a Bas Module
Notes:  In whatever module you add this code,
           (recommend using subMain in a standard module as your startup)
            the declaration of Public will
             make your class visible throughout your project.  You have to set 
a reference
             to the variable "clsMyClass" ONCE to instantiate the Class Object,
             thereafter you set a value to it and the class private variable
             " mvMyClassVar" will hold the value for reference whenever you 
request it as
             in the example sub "RetrieveTheValue"

+++++++++++++++++++++++++++++++
Option Compare Database
Public clsMyClass As clsMyProp

Private Sub ClassMyProp()
  Set clsMyClass = New clsMyProp
  clsMyClass.MyClassValueToStore = "TheOneShotValue"
  RetrieveTheValue
End Sub
Private Sub RetrieveTheValue()
  MsgBox clsMyClass.MyClassValueToStore
End Sub
+++++++++++++++++++++++++++++++++++++++++



<bobg.hahc@gmail.com> wrote in message 
news:0268b691-fced-486b-aa3f-b2662a0a8d8c@j20g2000hsi.googlegroups.com...
> On Feb 4, 7:47 pm, "MikeB" <m.byerleyATVerizonDottieNettie> wrote:
>> "Marshall Barton" <marshbar...@wowway.com> wrote in message
>>
>> news:rlcfq3945lfvjo80fqtlet8ui7docq0rof@4ax.com...
>>
>> > bobg.h...@gmail.com wrote:
>>
>> > A one row (one field?) table is the natural choice in a
>> > database system.
>>
>>   or a dozen lines in a Class module...
>>
>
> Hmm....
> Mike - interesting idea; although, admittedly, I haven't done much
> with classes...
> You don't have to spell out every letter, but could you give me an
> idea of how this would work?
>
> TX IA!
> Bob 


0
MikeB
2/5/2008 10:03:01 PM
A class may be more "elegant" in a computer science sort of
way and it's worth considering if you have a lot of things
to keep track of.

A custom property is also valid.

Both of those require some code to create, but IMO, their
limited scope is the deciding factor.  A trivial public
function that retrieves a variable's value and an always
open form's controls both have a scope that extends to
control expressions, queries as well as VBA procedures.
-- 
Marsh
MVP [MS Access]


bobg.hahc@gmail.com wrote:
>TX, this sounds like a very workable solution, and I definitely like
>it better than a global variable... I'll give it a try...
>
>
>On Feb 4, 6:54 pm, Marshall Barton <marshbar...@wowway.com> wrote:
>> bobg.h...@gmail.com wrote:
>> >running access 2k;
>> >When my application starts, the user is prompted to make a selection
>> >from a list.
>> >I want that selection to go into a global variable, and NEVER CHANGE
>> >while the application is running. This means that if the application
>> >encounters an unexpected error - this value is NOT lost.
>>
>> >If the user wants to change this value, they should have to close the
>> >application and restart.
>>
>> >This is the BEHAVIOR I'm looking for.....
>>
>> >Is this behavior possible, and if so, how?
>>
>>
>> Putting the value in a text box on an always open, hidden
>> form is much safer then a global variable.
>>
>> A one row (one field?) table is the natural choice in a
>> database system.
0
Marshall
2/5/2008 11:06:54 PM
FWIW, i use >private< global variables, with matching Get/Set routines.
Set: assign value to the global variable AND store it in a local table, 
"tblUserSetting"
Get: returns the value of the global variable. If that value (0 or "") 
indicates its been reset, retrieve it from tblUserSetting (or prompt user).

On Startup, you can also grab the value from tblUserSetting to "preselect" a 
value for the user to chose from.
-- 
HTH,
George



<bobg.hahc@gmail.com> wrote in message 
news:28984dfe-848b-4ce1-9d6a-e7259a787532@s19g2000prg.googlegroups.com...
> AHH....
> a lookup table in the front-end.... yea, performance should be much
> less an issue with that, but I still think dlookup is costly....
>
> But; I'll keep that in mind; in situations that may be the best
> solution....
>
> And, actually, I hadn't thought to use properties... I already use
> them for app version reporting, and such...
> Not hard to use at all.... and probably "cheaper" than a dlookup even
> to a local table.....
>
>
> TX!
>
> On Feb 5, 2:18 pm, "Jeanette Cunningham"
> <n...@discussions.microsoft.com> wrote:
>> If the table is in the front end, the performance issue is a non-issue, 
>> the
>> user is only fetching the data from a table stored on their own desktop -
>> nothing needs to be fetched from linked tables across the network.
>>
>> Jeanette Cunningham
>>
>> <bobg.h...@gmail.com> wrote in message
>>
>> news:54c2f1a7-68e1-41bb-9db9-0e972000c818@f10g2000hsf.googlegroups.com...
>>
>> > Linq:
>>
>> > I appreciate your reply...
>>
>> > I should have mentioned that I did think of storing it in a table...
>> > I just shy away from doing this, because of performance... there's
>> > dlookup; which is Really bad (performance-wise).
>> > I could always do a sql call, but prefer to just grab it out of memory
>> > if at all possible....
>>
>> > Of course, this would have been a fall-back position, saving any other
>> > ideas....
>>
>> > TX again!
>> > Bob
>>
>> > On Feb 4, 5:41 pm, "Linq Adams via AccessMonster.com" <u28780@uwe>
>> > wrote:
>> >> The only thing that comes to mind would be to have a utility table 
>> >> that
>> >> you
>> >> write this value to when your app opens, then either refer to it 
>> >> directly
>> >> each time you need it, or, if you are a good do-bee and have error
>> >> handling
>> >> routines on all procedures, re-assign it to a global variable if an 
>> >> error
>> >> is
>> >> encountered.
>>
>> >> I use such a table for holding things like company addresses, phones
>> >> numbers,
>> >> fax numbers, etc, that are used in printouts. That way, if any of 
>> >> these
>> >> things change, the end user can change the information, which wouldn't 
>> >> be
>> >> possible if it
>> >> were hardwired. You can also use it to store information about the 
>> >> last
>> >> record that was worked on, so that the user can pick up where they 
>> >> left
>> >> off.
>>
>> >> --
>> >> There's ALWAYS more than one way to skin a cat!
>>
>> >> Answers/posts based on Access 2000/2003
>>
>> >> Message posted viahttp://www.accessmonster.com
> 


0
George
2/6/2008 1:36:24 AM
Mike;

terrific information!
microsoft does have some good info - IF you can find it :) that link
was VERY helpful, but your example was much better at illustrating the
concept...

appreciate it... TX;

I think I will try to use this to manage my application setting...
just seems "cleaner" :-)
Bob

On Feb 5, 4:03 pm, "MikeB" <m.byerleyATVerizonDottieNettie> wrote:
> Here is a more detailed link:
>
> http://support.microsoft.com/kb/209968
>
> Here is a simple example:
>
> Add a Class Module to your project called clsMyProp
>
> Add the following Code to the module:
> +++++++++++++++++++++++++++++++
> Option Compare Database
> Option Explicit
>
> Private mvMyClassVar As String
>
> Private Sub Class_Initialize()
>   'if you wanted a Default Startup Value
>   'You would set it here:
>   'mvMyClassVar = "Initialized"
> End Sub
>
> Public Property Let MyClassValueToStore(s As String)
>    mvMyClassVar = s
> End Property
>
> Public Property Get MyClassValueToStore() As String
>    MyClassValueToStore = mvMyClassVar
> End Property
>
> Private Sub Class_Terminate()
>    'Any Cleanup Code for the Class you Would do Here
>    'MsgBox "Class Terminated", vbInformation, "Class Example"
> End Sub
>
> +++++++++++++++++++++++++++++++
>
> Add the following Code to a Form module or a Bas Module
> Notes:  In whatever module you add this code,
>            (recommend using subMain in a standard module as your startup)
>             the declaration of Public will
>              make your class visible throughout your project.  You have to set
> a reference
>              to the variable "clsMyClass" ONCE to instantiate the Class Object,
>              thereafter you set a value to it and the class private variable
>              " mvMyClassVar" will hold the value for reference whenever you
> request it as
>              in the example sub "RetrieveTheValue"
>
> +++++++++++++++++++++++++++++++
> Option Compare Database
> Public clsMyClass As clsMyProp
>
> Private Sub ClassMyProp()
>   Set clsMyClass = New clsMyProp
>   clsMyClass.MyClassValueToStore = "TheOneShotValue"
>   RetrieveTheValue
> End Sub
> Private Sub RetrieveTheValue()
>   MsgBox clsMyClass.MyClassValueToStore
> End Sub
> +++++++++++++++++++++++++++++++++++++++++
>
> <bobg.h...@gmail.com> wrote in message
>
> news:0268b691-fced-486b-aa3f-b2662a0a8d8c@j20g2000hsi.googlegroups.com...
>
> > On Feb 4, 7:47 pm, "MikeB" <m.byerleyATVerizonDottieNettie> wrote:
> >> "Marshall Barton" <marshbar...@wowway.com> wrote in message
>
> >>news:rlcfq3945lfvjo80fqtlet8ui7docq0rof@4ax.com...
>
> >> > bobg.h...@gmail.com wrote:
>
> >> > A one row (one field?) table is the natural choice in a
> >> > database system.
>
> >>   or a dozen lines in a Class module...
>
> > Hmm....
> > Mike - interesting idea; although, admittedly, I haven't done much
> > with classes...
> > You don't have to spell out every letter, but could you give me an
> > idea of how this would work?
>
> > TX IA!
> > Bob

0
bobg
2/6/2008 7:13:02 PM
I think what I like about the class solution is this - and it is a
guess on my part:
it seems to me that the class solution would utilize less system
resources than having a form & control open & hidden all the time.

granted, the resources in question are no doubt trivial, so maybe it
is more an intellectual comfort of know that I saved 5 bytes of
memory... ;-)

Bob

On Feb 5, 5:06 pm, Marshall Barton <marshbar...@wowway.com> wrote:
> A class may be more "elegant" in a computer science sort of
> way and it's worth considering if you have a lot of things
> to keep track of.
>
> A custom property is also valid.
>
> Both of those require some code to create, but IMO, their
> limited scope is the deciding factor.  A trivial public
> function that retrieves a variable's value and an always
> open form's controls both have a scope that extends to
> control expressions, queries as well as VBA procedures.
> --
> Marsh
> MVP [MS Access]
>
> bobg.h...@gmail.com wrote:
> >TX, this sounds like a very workable solution, and I definitely like
> >it better than a global variable... I'll give it a try...
>
> >On Feb 4, 6:54 pm, Marshall Barton <marshbar...@wowway.com> wrote:
> >> bobg.h...@gmail.com wrote:
> >> >running access 2k;
> >> >When my application starts, the user is prompted to make a selection
> >> >from a list.
> >> >I want that selection to go into a global variable, and NEVER CHANGE
> >> >while the application is running. This means that if the application
> >> >encounters an unexpected error - this value is NOT lost.
>
> >> >If the user wants to change this value, they should have to close the
> >> >application and restart.
>
> >> >This is the BEHAVIOR I'm looking for.....
>
> >> >Is this behavior possible, and if so, how?
>
> >> Putting the value in a text box on an always open, hidden
> >> form is much safer then a global variable.
>
> >> A one row (one field?) table is the natural choice in a
> >> database system.

0
bobg
2/6/2008 7:18:04 PM
George,
TX much for your input.

I actually also use the technique for other "user", or "system" type
settings. It just seemed a little "un-permanent" for what I wanted to
do here.

although, your comment leaves me with another idea of using this
technique with classes... again not for this specific situation, but
for many others...

good tip... TX

On Feb 5, 7:36 pm, "George Nicholson" <GeorgeNJ...@Junkmsn.com> wrote:
> FWIW, i use >private< global variables, with matching Get/Set routines.
> Set: assign value to the global variable AND store it in a local table,
> "tblUserSetting"
> Get: returns the value of the global variable. If that value (0 or "")
> indicates its been reset, retrieve it from tblUserSetting (or prompt user).
>
> On Startup, you can also grab the value from tblUserSetting to "preselect" a
> value for the user to chose from.
> --
> HTH,
> George
>
> <bobg.h...@gmail.com> wrote in message
>
> news:28984dfe-848b-4ce1-9d6a-e7259a787532@s19g2000prg.googlegroups.com...
>
> > AHH....
> > a lookup table in the front-end.... yea, performance should be much
> > less an issue with that, but I still think dlookup is costly....
>
> > But; I'll keep that in mind; in situations that may be the best
> > solution....
>
> > And, actually, I hadn't thought to use properties... I already use
> > them for app version reporting, and such...
> > Not hard to use at all.... and probably "cheaper" than a dlookup even
> > to a local table.....
>
> > TX!
>
> > On Feb 5, 2:18 pm, "Jeanette Cunningham"
> > <n...@discussions.microsoft.com> wrote:
> >> If the table is in the front end, the performance issue is a non-issue,
> >> the
> >> user is only fetching the data from a table stored on their own desktop -
> >> nothing needs to be fetched from linked tables across the network.
>
> >> Jeanette Cunningham
>
> >> <bobg.h...@gmail.com> wrote in message
>
> >>news:54c2f1a7-68e1-41bb-9db9-0e972000c818@f10g2000hsf.googlegroups.com...
>
> >> > Linq:
>
> >> > I appreciate your reply...
>
> >> > I should have mentioned that I did think of storing it in a table...
> >> > I just shy away from doing this, because of performance... there's
> >> > dlookup; which is Really bad (performance-wise).
> >> > I could always do a sql call, but prefer to just grab it out of memory
> >> > if at all possible....
>
> >> > Of course, this would have been a fall-back position, saving any other
> >> > ideas....
>
> >> > TX again!
> >> > Bob
>
> >> > On Feb 4, 5:41 pm, "Linq Adams via AccessMonster.com" <u28780@uwe>
> >> > wrote:
> >> >> The only thing that comes to mind would be to have a utility table
> >> >> that
> >> >> you
> >> >> write this value to when your app opens, then either refer to it
> >> >> directly
> >> >> each time you need it, or, if you are a good do-bee and have error
> >> >> handling
> >> >> routines on all procedures, re-assign it to a global variable if an
> >> >> error
> >> >> is
> >> >> encountered.
>
> >> >> I use such a table for holding things like company addresses, phones
> >> >> numbers,
> >> >> fax numbers, etc, that are used in printouts. That way, if any of
> >> >> these
> >> >> things change, the end user can change the information, which wouldn't
> >> >> be
> >> >> possible if it
> >> >> were hardwired. You can also use it to store information about the
> >> >> last
> >> >> record that was worked on, so that the user can pick up where they
> >> >> left
> >> >> off.
>
> >> >> --
> >> >> There's ALWAYS more than one way to skin a cat!
>
> >> >> Answers/posts based on Access 2000/2003
>
> >> >> Message posted viahttp://www.accessmonster.com

0
bobg
2/6/2008 7:23:28 PM
Hey Mike-

I have to say using classes, I was able to create a very elegant
solution that does ALMOST exactly what I want!

I created a property, that basically check's to see if the property is
already null. if it is null, it set's it; if not, it raises an error
"one-time write property".

VERY nice; except that an un-handled error still clears the class
variable....

any way around this that you know of.... (again the "real" desire is
to do this without the use of tables as an intermediate storage - I
can do this if I used a "session stamped record" in a table).

TX again!
Bob

On Feb 4, 7:47 pm, "MikeB" <m.byerleyATVerizonDottieNettie> wrote:
> "Marshall Barton" <marshbar...@wowway.com> wrote in message
>
> news:rlcfq3945lfvjo80fqtlet8ui7docq0rof@4ax.com...
>
> > bobg.h...@gmail.com wrote:
> > I want a constant, that I can set from a variable (one time)!!!
> >
>
>   or a dozen lines in a Class module...
>






0
bobg
2/6/2008 9:14:45 PM
"Marshall Barton" <marshbarton@wowway.com> wrote in message 
news:8bqhq39m679cd6rvgtrvkrhd4ntj34morq@4ax.com...
>A class may be more "elegant" in a computer science sort of
> way and it's worth considering if you have a lot of things
> to keep track of.
>
> A custom property is also valid.
>
> Both of those require some code to create, but IMO, their
> limited scope is the deciding factor.  A trivial public
> function that retrieves a variable's value and an always
> open form's controls both have a scope that extends to
> control expressions, queries as well as VBA procedures.

All solutions have their time and purpose.
Classes, though slightly more comples than a public variable go the additional 
step of providing information hiding.
The liklihood of tromping on a public variable is measurably greater than the 
inadvertant access and disturbance of a property in a class.
You choose the solution that fits the circumstances.

> Marsh
> MVP [MS Access]
>
>
> bobg.hahc@gmail.com wrote:
>>TX, this sounds like a very workable solution, and I definitely like
>>it better than a global variable... I'll give it a try...
>>
>>
>>On Feb 4, 6:54 pm, Marshall Barton <marshbar...@wowway.com> wrote:
>>> bobg.h...@gmail.com wrote:
>>> >running access 2k;
>>> >When my application starts, the user is prompted to make a selection
>>> >from a list.
>>> >I want that selection to go into a global variable, and NEVER CHANGE
>>> >while the application is running. This means that if the application
>>> >encounters an unexpected error - this value is NOT lost.
>>>
>>> >If the user wants to change this value, they should have to close the
>>> >application and restart.
>>>
>>> >This is the BEHAVIOR I'm looking for.....
>>>
>>> >Is this behavior possible, and if so, how?
>>>
>>>
>>> Putting the value in a text box on an always open, hidden
>>> form is much safer then a global variable.
>>>
>>> A one row (one field?) table is the natural choice in a
>>> database system. 


0
MikeB
2/7/2008 4:38:49 AM
Reply:

Similar Artilces:

VBA code to find all formula cells with a variable and a constant
Using XL 2003 & 97 Not yet successful at trying to write VBA code to find all formula cells with a variable AND a constant. Also, I would like each identified cell to background-fill with yellow. Example: (Cells A2 & A3 are background-filled yellow) A1 = B1+C1 (Not selected - background no-fill) A2 = B2+10000+C2 (Selected - background - yellow) A3 = B1+C1+15000 (Selected - background - yellow) TIA Dennis ...

I cannot display all the poly equation constants on the chart.
Using 2007: when openning up a 2000 spreadsheet, a chart that used to display the equation for a 6th order poly only displays the the last 3 constants. I have looked at the trendline formating tools available and every thing is set correctly. The trendline is drawn correctly and changes, as you would expect, when I increase the poly order. I've heard of issues with Excel 2007's display of the polynomial formula. You could get the values in the worksheet using LINEST, as Bernard explains: http://people.stfx.ca/bliengme/ExcelTips/Polynomial.htm Keep in mind that a sixth order fi...

Word Constantly Crashing 01-07-10
Version: 2008 Operating System: Mac OS X 10.6 (Snow Leopard) Processor: Intel Hi All, <br><br>I have been experiencing constant crashes in Word lately. Office is fully patched to 12.2.3, I have tried removing the Microsoft User Data folder and letting Office re-create everything, and forced Office to re-created the plist files. I have also removed all the trouble fonts, as i have seen in multiple posts here. I get the following error message: <br><br>Microsoft Error Reporting log version: 2.0 <br><br>Error Signature: <br> Exception: EXC_BAD_ACC...

text search for a non-constant value?
Hi! The seach/3 function searches for 'find_text' in 'within_text', starting at the 'start_nun's character: SEARCH(find_text,within_text,start_num) I need to find the first digit in a string. I guess, search/3 does neither support regular expresseions, no does it allow a function instead of a constant 'search_text'. One way to find the first digit is this monster: =MIN( IF(ISNUMBER(SEARCH(0;D2));SEARCH(0;D2);9999); IF(ISNUMBER(SEARCH(1;D2));SEARCH(1;D2);9999); IF(ISNUMBER(SEARCH(2;D2));SEARCH(2;D2);9999); IF(ISNUMBER(SEARCH(3;D2));SEARCH(3;D2);9...

Copy records automatically to another sheet based upon constant criteria
I have 1000+ address lines (name, address, phone) in a single sheet. I would like to make a copy, which will update, based upon constant criteria. Ex: I would like to copy all records which have 561 area code and place them on another sheet, all 856 on another and so on. Changes made to the "master" sheet would automatically update on the appropriate sheet - additions, changes, etc... Can anyone assist? Thank you in advance. On Jul 1, 8:41=A0am, skiing <trpa...@chatt.com> wrote: > I have 1000+ address lines (name, address, phone) in a single sheet. > I would like to mak...

Constant number of lines per group
I need to print a constant number of lines per group, as my report needs to print on pre-printed forms, and the data needs to land in the correct location on the paper. I found the following support article on Microsoft's web site, but it indicates that it works only through version 97. Hoping it would still work anyway, I followed the instructions, but it did not work for me in Access 2007. http://support.microsoft.com/kb/q119073 Does anybody know how to accomplish this in 2007? TIA. "... did not work ... in Access 2007" does not tell us much. Did Access print anything?...

Public Constant not visible in worksheet?
Office / Excel 2003 SP3 XP Pro SP3 I'm writing some code that I'd like to be available to every worksheet in the workbook, and for a variety of reasons I'm trying to avoid using PERSONAL.XLS and/or addins. [The object of the exercise is to allow any user within the organization to be able to utilize the macros in this workbook as long as (s)he has a standard Office installation.] I've written sub procedures in a standard module in the workbook / project that are called from a Worksheet_Changed event .... the code works as expected. My problem is when I attempted to rep...

Formula vs Constant #2
Is there a formula that will check a cell to determine if it is a constant (123) vs a formula (=a1)? Only if you use a UDF http://www.mvps.org/dmcritchie/excel/formula.htm#HasFormula -- Regards, Peo Sjoblom (No private emails please, for everyone's benefit keep the discussion in the newsgroup/forum) "Jonathan Cooper" <JonathanCooper@discussions.microsoft.com> wrote in message news:2ED0251B-E26A-46C3-803C-9B8FA51EEE5D@microsoft.com... > Is there a formula that will check a cell to determine if it is a constant (123) vs a formula (=a1)? Jonathan User Defined ...

Pivot Tables
I am trying to divide my pivot table output by a constant (which is 5.05). The tabulated output is summarised by the "Sum" function which has been selected in the PivotTable Field dialogue box. I have invoked Options and examined the further dropdown selections from the "Show Data As" and "Base Filed" options - but I am lost. What I am trying to achieve is so simple, but it defeats me. Of couse I can divide my base data by the constant - but I dont want to do that. I was hoping the resultant pivot table could be produced such that ir could divide the values it ...

Copy Constants Only
Hi, Need to copy all "values" or "constants" (not Formulas) from one sheet to another sheet in a different workbook. I did the following: Edit -->Go To then Special (from dialogue box) then "constants" I see all the cells that I want are selected. Then I tried to use the copy command but I got the error message: "that command cannot be used on a multiple selection". Any ideas is appretiated! Khalil Here is a method that works, Copy everything to the second sheet Not use Edit | Go To | Special | Formulas and tap the Delete key best wishes -- Ber...

VBA
I have created code that inserts lines into a financial statement but need to have certain cells in other code stay constant. B1 in certain code must stay at B1 regardless of changes to the spreadsheet. Any suggestions?? --- Message posted from http://www.ExcelForum.com/ Use the INDIRECT function. E.g., =INDIRECT("B1") The B1 will remain so regardless of inserting and deleting rows. -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "bforster1 >" <<bforster1.1cmxzp@excelforum-nospam.com> wrote in m...

Outlook97 scans floppy constantly.. Solved...finally.
I can't believe with all the people having this problem, and all the groups i've visited that I had to figure out this glitch on my own. None of the suggestions posted anywhere worked. And my problems were magnified since I had dozens of machines with this glitch to fix. Microsoft's KB support didn't help either. It was relatively easy to solve, but certain not very obvious.. So.....What was the fix? (So we can all learn) "Nate Goulet" <askifyouwantaaddress@yahoo.com> wrote in message news:3fc3915c.4612799@news.ids.net... > I can't believe with all t...

how can i obtain polynomial constants when using trendlines.
how can i obtain polynomial constants when using trendlines. i sometimes need to used these constants in other calculations but must manually enter them in another context. Hi, Let's suppose that the x- and y- ranges are in A2:A51 and B2:B51 respectively, and you are fitting a 6-order polynomial to your data. Select a 7 column x 1 row area, enter the following formula, and confirm with CTRL-SHIFT-ENTER. =LINEST(B2:B51,A2:A51^{0,1,2,3,4,5,6},0,) The formula will return the 7 coefficients, starting from the zeroth order and ending with the 6th order. If you want to have the co...

Constant Values
I am trying to assign constant values to the heading of a spreadsheet that I am creating so that when I put in the quantity of product that someone order is will automatically calculate the total cost for that one product, any suggestions? Total cost = qty * price A1 = qty 10 B1 = price 10.00 C1 = total cost formula =A1*B1 Biff >-----Original Message----- >I am trying to assign constant values to the heading of a spreadsheet that I am creating so that when I put in the quantity of product that someone order is will automatically calculate the total cost for that one product, an...

Regions of Constant Slope
I have a set of data x, y and want to find regions (or ranges) of "constant" slope and I want the value of the slope and range x of that "constant" slope. I'm not exactly sure what I mean by "constant" (note the quotes) but believe I *may* be able to use RSQ (R-Squared) to define it. I *believe* I may have to do it in VBA as I want to automate it - but again - I'm not sure. Your help is greatly appreciated. Thank you! The slope between data points can be defined by: slope = (y2 - y1) / (x2 - x1) So say your x data is in column A ...

formulas containing constants
Hi, it's been a long time since I have worked with formulas and I am having problem with a formula that is working with constants. My formula is: =IF(OR(B2=$G2,B2=$G3,B2=$G4,B2=$G5),"Already set up","Not set up") G2 through G5 should remain constant. What am I doing wrong? -- Kelly Not exactly clear what you mean by constant, but I will guess that you need =IF(OR(B2=$G$2,B2=$G$3,B2=$G$4,B2=$G$5),"Already set up","Not set up") so that the row number does not change when you copy the formula. Tom "fentonas1" wrote: ...

DVD maker crashes constantly
It seems to only crash when I am using an xvid file or more than 1 file onto a dvd. Here is the error report: Problem signature Problem Event Name: APPCRASH Application Name: divxsm.exe Application Version: 6.9.1.0 Application Timestamp: 4ab3d369 Fault Module Name: qt-dx331.dll Fault Module Version: 6.0.6002.18005 Fault Module Timestamp: 49e03821 Exception Code: c0000135 Exception Offset: 00009eed OS Version: 6.0.6002.2.2.0.768.3 Locale ID: 1033 Additional Information 1: 9d13 Additional Information 2: 1abee00edb3fc1158f9ad6f44f0f6be8...

Outlook 03 crashes constantly
I installed Outlook 03 a week or so ago and although I like the look, feel and new features the damn thing crashes all the time. It just freezes and I have to use the task manager to shut it down. Even after that I still have the icon in the task tray and I have to close it through the processes screen. Anyone else have this problem? Is there a fix? Thanks Try a new mail profile. --� Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. Due to the (insert latest virus name here) virus, all mail sent to my personal account will be deleted witho...

Loop Enumeration Constants
All, I'm curious to know if there is a way to loop through the constants of an enumeration. (Or, maybe another way to put this is this: Is there a way to get an enumeration as a collection?) I'll illustrate with a simple example below ("TestEnumLoop"), which puts the constants of XlYesNoGuess into an array, loops through the array, and prints the constant values to the Immediate Window. (Continue reading after "TestEnumLoop" for the "hypothetical code"). Sub TestEnumLoop() Dim varArr As Variant Dim varItem As Variant 'Dim xlE...

Set a date as a constant to work back from to show only weekdays #2
I would like to input one date as a constant and then apply a formaula in other cells relating to this date to calculate back from but to "round" back to only weekdays. For example if i type in a date of February 1st 2006 (a Wednesday) and would like to calculate backwards automatically by eleven days it is Sat Jan 21st 2006. I would like this to round back to the nearest previous workday which would be the Friday. On Sun, 8 Jan 2006 19:11:02 -0800, "Happy Gilmore" <Happy Gilmore@discussions.microsoft.com> wrote: >I would like to input one date as a constant...

Using Access 2007 User Constants in Word 2007
I want to start Word using Access (which I can already do) and then immediately use Access to assign values to Word constants. How is that done? Umm. The definition of "constant" is that you can't change the value! The idea of "assigning values to Word constants" doesn't really make sense. Perhaps you'll need to give a bit more detail of what it is you're trying to do. -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-mails, please!) "LA Lawyer" <hkapp@kapplaw.com> wrote in message news:eocDyH...

Outlook crashes constantly
I have a really weird problem. I was just trying to add a meeting to my calendar when I got an error message : "Microsoft Office Outlook has encountered a problem and needs to close. We are sorry for the inconvenience." So I checked the box restart Outlook and clicked on ok, but it happened again. In fact now it happens every time I try to run Outlook. I can start Outlook in safe mode without problems, I can access Calendar , Inbox , Tasks ... Every time I try to start in normal mode I get the error message. Tried to run scanpst - told me that it found some errors in pst file an...

? Define Constant Name Strings to Integer Values
Hi, I'm looking for a way to convert a defined constant from its name to its value. For example I need a way to take the input string "VK_ESCAPE" and derive its integer value 0x1b. Most scripting languages do this through the eval function, but I cannot figure out a way to accomplish this with VC++. (I'm writing a dialog app, and I need a way to allow the user to pass key names on the command line without reinventing an entire key-map.) Any ideas? Thanks. -- Alec S. news/alec->synetech/cjb/net There may be a trickier way, but I would just build a switch statement...

Please help
Outlook XP constantly freezes up (gives me the not responding text at the top of the window). It locks up more frequently with larger files. I have downloaded all the patches and updates fro Microsoft's webpage. Any help will be greatly appreciated. Often the only way to read e-mail is to start Outlook in safe mode. I have tried the detect and repair function to no avail. Please Help. Thanks, Scott Locks up when? When downloading new e-mail? Since it works in safe mode I expect your incoming virusscan may be the issue here. -- Robert Sparnaaij [MVP-Outlook] www.howto-outl...

Trouble linking workbooks in excel to stay constant
I have a problem with my linking remaining constant between two work books. I am linking 2 cells in 2 separate workbooks using the following formula: ='[2009 Project Tracking ~ Sheila.xls]G5827'!$A$21 When I insert a row above A21 in the source workbook the formula automatically updates to: ='[2009 Project Tracking ~ Sheila.xls]G5827'!$A$22 What I am trying to do is keep the cell constant and have the link stay with that new row. The purpose is one workbook only contains the most current update and the source workbook retains historical data. Any help is greatly appreciate...