none
Variable in constant ? RRS feed

  • Question

  • Hello,

    If I remember well, it was possible to store a variable in a "constant" outside the VBA proc, and use it some time after in another proc.

    How to do that. I searched about Const but with no avail.

    Thanks

    Friday, October 7, 2016 3:19 PM

Answers

  • Hi WLID,

    I assume you are referring to a global variable. Just don't define it with "Dim" inside a prc, but outside with "Public". Any value you are setting to this public vatiale inside a proc (e.g. in forms code), you can use in another proc - as long as they are in the same "session".

    Is that what you are looking for?
    Regards
    Barbara


    To increase the value of this forum, please mark the replies that helped to solve your issue as answer. If you find answers to questions from other forum participants to be helpful, please mark them as helpful. Your participation will help others to find an appropriate solution faster. Thanks for your support!

    • Marked as answer by WLID1966 Friday, October 7, 2016 5:09 PM
    Friday, October 7, 2016 4:39 PM
    Moderator
  • WLID1966,

    Although it may be possible to do this is it really necessary? Several years ago I had a need to store a couple pieces of data outside of a Project VBA procedure. Rod Gill introduced me to the SaveSetting and GetSetting VBA functions, so you might want to look into those, otherwise, depending on the circumstances, you might be able to simply save the value to an extra field of the Project Summary Task such that any subsequent procedure can retrieve and use it.

    John

    • Marked as answer by WLID1966 Friday, October 7, 2016 5:09 PM
    Friday, October 7, 2016 4:40 PM

All replies

  • Hi WLID,

    I assume you are referring to a global variable. Just don't define it with "Dim" inside a prc, but outside with "Public". Any value you are setting to this public vatiale inside a proc (e.g. in forms code), you can use in another proc - as long as they are in the same "session".

    Is that what you are looking for?
    Regards
    Barbara


    To increase the value of this forum, please mark the replies that helped to solve your issue as answer. If you find answers to questions from other forum participants to be helpful, please mark them as helpful. Your participation will help others to find an appropriate solution faster. Thanks for your support!

    • Marked as answer by WLID1966 Friday, October 7, 2016 5:09 PM
    Friday, October 7, 2016 4:39 PM
    Moderator
  • WLID1966,

    Although it may be possible to do this is it really necessary? Several years ago I had a need to store a couple pieces of data outside of a Project VBA procedure. Rod Gill introduced me to the SaveSetting and GetSetting VBA functions, so you might want to look into those, otherwise, depending on the circumstances, you might be able to simply save the value to an extra field of the Project Summary Task such that any subsequent procedure can retrieve and use it.

    John

    • Marked as answer by WLID1966 Friday, October 7, 2016 5:09 PM
    Friday, October 7, 2016 4:40 PM
  • Thanks Barbara

    Yes it is what I was looking for!

    Friday, October 7, 2016 5:09 PM
  • Thanks John

    I'll study SaveSetting and GetSetting functions.

    Friday, October 7, 2016 5:11 PM
  • WLID1966,

    You're welcome and thanks for the feedback.

    John

    Friday, October 7, 2016 5:26 PM