Validate UserForm MultiPage and Frame Controls

  • Hi Guys & Gals,


    I am in the process of creating a module to validate a MulitPage UserForm that is composed of, among other controls, multiple frames, each containing a TextBox and two OptionButtons. I need to identify those frames where the TextBox value is not null and neither of the OptionButtons have been selected. The module will pass as variables the TextBox value, OptionButton captions and Frame caption to another module that will create a UserForm with the invalid Frame/TextBox/OptionButtons sets for the user to correct.


    The interim code listed below runs as a command button on a test UserForm. The MsgBox displays only the first of the OptionButton’s caption as Opt1 and Opt2. Can anyone tell me why and where I went awry?


    Is there a more elegant way of accomplishing this? (Control Tags are already spoken for.)


    Many Thanks,


    John

  • Re: Loop Through Multiple Sets Of Controls As Validation


    Use this.


  • Re: Validate UserForm MultiPage and Frame Controls


    Hi Dave,


    Many thanks for your rapid reply. Let me clarify, if I may. I already have two other validation message boxes running on the multipage form. My initial inclination was that having a third would annoy the user. That is why my initial scheme was to have this particular validation module run as part of a submit module and show a user form that collates all failed frame sets. (Rather than the focus returning to the page, jumping through the pages)


    Nevertheless, if I were to decide on creating a third message box, I’m not sure how to code “Please select an option” that will be invoked when only those TextBoxes associated with a Frame lose focus outside the Frame. To clarify: The code will run only when a TextBox contains data and neither of the two associated OppionButtons have been selected. (Typically, not every TextBox contains data.)


    Also, I am unclear why the code I submitted doesn’t yield the correct OptionButton caption.


    Last, when running a For command how are the controls parsed? I.e., what determines the sequence in which the controls are analyzed?


    Warm regards,


    John

  • Re: Validate UserForm MultiPage and Frame Controls


    The message boxes are optional. You should really validate each page of the MutiPage as the user changes pages via its Change Event.


    Or, only Enable Controls as the user moves through them. For example, only enable a TextBox when they have chosen an Option from a group of OptionButtons.

  • Re: Validate UserForm MultiPage and Frame Controls


    Hi Dave,


    I took your suggestion to validate as the user migrates though the form. The code I developed and listed below works exactly as I want it to. Once the Frame loses focus the code initiates and tests the Frame's OptionButtons if and only if the TextBox contains a value, restoring the focus. The test Frame's name is Frame22.



    What I'd like to do is to make this a class module that will operate on the relevant Frame/TextBox/2 X OptionButtion groups that span the MultiPage Userform. I'm not sure how to do this; Not how to create a class module but the syntax to execute this code within the Frames.


    Also, the code you kindly provided acted kinda funky in that it halted with an error at the code line "cCtrlF.SetFocus"


    Many thanks for any suggestions.


    Warm regards,


    John