Calling a userform and returning a value

后端 未结 3 1901
北恋
北恋 2020-12-11 17:39

I have a vba code thats Auto_Open. It does some checks then prompts a userform that asks for username and password. I called this userform with userform_name.show

3条回答
  •  盖世英雄少女心
    2020-12-11 18:28

    You can manage to do this without the use of public variables.

    There appears to be a difference between show/hide and load/unload.

    If you hide a form while it's still loaded it won't be cleared out, so you can reference the state of the controls on the form.

    For example I was using a date picker (called DTPicker1) on a form, my code in the module looks something like this:

    Dim NewDay As Date
    
    Load FrmDayPicker
    FrmDayPicker.Show
    
    NewDay = FrmDayPicker.DTPicker1.Value
    
    Unload FrmDayPicker
    
    Debug.Print NewDay
    

    On your form you can just use Me.Hide insteaded of Unload Me and this should work

提交回复
热议问题