Discussion Locked

Retain data value from form to module

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I have a switch that is set to a value in a form subroutine.
I need to know how to transfer that switch value from the form subroutine to a module subroutine.

5 replies

by john_wills

If you are working in VBA - you do not say - probably what you need, if you cannot pass the switch as a parameter, is a public variable in the form module, in the code module, or in your main code module; assign a value to the public variable in theform subroutine and use the public variable in the code module's subroutine.

by darryl severn

In a similar vein to the previous answer, you could set up a public variable in the module and reference that from the form subroutine. Don't forget that to reference a var in another form or module that you need to prefix it with the name of the form or module e.g. form.var

This type of solution pre-supposes that both the form and module are in existance at the same time. If not, you need to create some persistant data. Assuming you are in a single process type environment, i.e. there is only ever going to be one valid value for this switch at any one time, you could write the value out to a key in the registry from within the form and then read it in from within the module. The same holds true with the property bag, although I have never used the property bag in anything more than an experiment.

If you are in a multi-process evnivronment, I would be inclined to write the data out to a file which included the switch value itself, and some way of identifying the owning process.
No doubt other people have other views on this.

This discussion is closed to new replies.