Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2013

    Unanswered: Defining and changing constants through a form?


    Im currently making a small db to calculate budgets and some prices have to be multiplied by a factor which i need the user to be able to both view and change via form.

    I tried creating a module which allocated the value of a textbox from the form into a function this way:

    Public Function constantname() As Double
    constantname = Forms!formname!txtbox
    End Function

    But it has two problems:

    1) The form needs to be open for , say, a query to use the constant
    2) The constant is always null unless i open the form and place a value on the texbox (ie it doesnt "remember" the value i put earlier)

    Which render the thing useless.

    I also tried defining a function
    Public Function constantname() As Double
    End Function

    and through an afterupdate event defining it as the value of the textbox but im not even sure if i can do that.. it certainly didn't work.

    Can somebody give me a hand? I guess i could create a table, define a field for every constant i need, and populate it with a single record, but i kinda want to do it the right way so i learn as i do it.
    Thank you!
    Last edited by JoacoSM; 01-14-15 at 12:43.

  2. #2
    Join Date
    Jun 2005
    Richmond, Virginia USA
    Provided Answers: 19
    I'm pretty sure that constants have to be declared/defined in Design View. Besides, which,

    Constants are meant to be...constant!

    Variables are meant to be...variable!

    Use a Public (global) Variable for this, in a Standard Module, if you're using Access 2003 or earlier, or TempVars is using 2007 or later. The TempVars can be declared and populated from the code module of Forms.

    Linq ;0)>
    Hope this helps!

    The problem with making anything that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts