PDA

View Full Version : VBA Forms and Modules



msretenovic
2004-10-29, 08:26 PM
Hello everyone,

Need a little help. I have a form in VBA and I need to pass one variable back to the module that called it. I have NO idea how to do this. I tried to set a public variable for this purpose, but the form gave me an error saying that the variable hasn't been declared.

Anyone care to give me a crash course in VBA forms? :D

TIA,

Ed Jobe
2004-11-01, 05:10 PM
There are a couple of ways you could do this.
1. Declare a global var in the calling module and then have the form set this var. Then the calling sub checks the var after the forms closes.
2. I prefer to create a property in the form. The form sets the property. Instead of closing the form, do a hide. The calling sub shows the form, waits for it to Hide, then checks the form's property and unloads the form. Advantage: the var goes out of scope when the form does. This works well the other way around as well. I load a form, set properties and then show it. For example, I may prompt the user for a selection set, filtering or processing it as necessary, save it to a collection and then pass the collection to the form for further processing.

msretenovic
2004-11-01, 06:36 PM
Thanks Ed, that was what I was looking for.

:)