Reputation: 1
I'm a novice at VBA programming who is currently undertaking an effort to understand the VBA code written by someone else who is no longer available to ask questions. There are several dozen pages of code - however, the part that's causing some concern for me right now can be described as follows:
There are 2 user forms. The program flow should be that UserForm1 asks for an account number, and then UserForm2 displays that account's information. Once the account information has been processed, then control should be returned to UserForm1 so that another account number can be obtained (or the program exited).
But within UserForm1 there's a call to UserForm2, and within UserForm2 there's a call to UserForm1. I'm finding that highly problematic and would like some advice on how to handle this situation appropriately. I've found plenty of information on the Internet regarding the creation and use of user forms, but nothing yet pertaining to the interaction between 2 user forms like this (with the exception of the article on this website entitled: VBA: Using Multiple User Forms, which makes me believe that perhaps UserForm1 should be “hidden” (i.e., UserForm1.hide) as opposed to being “unloaded” – I believe I can still use the “modal” mode, as opposed to the “modeless” mode which was suggested by the second response to the article). But this back-and-forth calling still has me somewhat confused…. Like I said, I’m a novice, so I’m somewhat limited in my understanding at this point.
Since the code is rather lengthy, I hope the following description will suffice.
Sub1
call to Sub2
Sub2
launches UserForm1 (unloads UserForm1 before launching UserForm2)
launches UserForm2 (unloads UserForm2 before launching UserForm1)
launches UserForm2 (unloads UserForm2 before launching UserForm1)
launches UserForm1 (unloads UserForm1 before launching UserForm2)
Now perhaps I'm just being too procedural in my thinking, but it would make more sense to me to compartmentalize the launching of UserForm1 & UserForm2 so there's not this back-and-forth calling going on. If someone could please correct me if my assumption is wrong, or offer some assistance if my assumption is correct, that would be greatly appreciated!
Upvotes: 0
Views: 209
Reputation: 11755
Open Userform2 modally instead.
Userform2.Show vbModal
Userform2 will display overtop of Userform1 then, and return control to Userform1 once it's unloaded.
Upvotes: 1