Multi-button Input Form with on-the-fly userform

  • In another thread, I mentioned an inputbox with more than two buttons. Here it is. I call this thing an InputForm.
    It's really a userform created on the fly. It is done by creating a new class, thingInputForm.


    To call the form, a variable is declared as the new data class.


    Code
    1. Dim userInput as New thingInputForm



    userInput.InputForm(Prompt,[Title],[Buttons],[Default],[dataType],[passwordChar]) calls the InputForm and the user makes their entry.


    A thingInputForm hold the results of the last user interface in the properties .Value and .Pressed.


    .Value is what was entered into the box with either the keyboard or mouse.
    .Pressed ,with no index , returns the number of the button that was pressed at the last user entry.
    .Pressed(i) returns a boolean value. True if button #i was the last pressed.


    .InputForm displays a input box with up to three buttons. InputForm returns the number of the button pressed (same as .Pressed) or False if the user Cancels.


    The arguments Prompt, Title, and Default are strings.


    Buttons is an optional argument. Setting it to vbOKOnly, vbOKCancel, vbYesNoCancel determines how many buttons are shown.
    Adding vbDefault1, 2 or 3 to that value changes the default. Those are the only button styles InputForm accepts.
    vbOKCancel is the default.


    dataType is as in an inputbox. 1-number,2-text,4-logical,8-range,16-error


    passwordChar will mask the characters for password entry. If passwordChar = False characters entered are displayed normaly. If True, a bullet will mask each character entered. A custom masking character can be entered as a string.


    This password demo shows the general syntax. The other demos in the attachment show other features.


    thingInputForm can easily be transmuted out of a class and into a function. The creeping feature creature prowls around a project like this. A fourth button and custom button caption arguments are a couple of features I rejected.


    The default button needs better bolding and the validation function typeOK is not too clean.


    I hope someone finds this useful.

  • Re: Multi-button Input Form with on-the-fly userform


    Thanks Mike. Well done.

    Regards,


    Wigi


    Excel MVP 2011-2014


    For more Excel memes: visit http://www.wimgielis.com ==> English articles ==> Excel memes


    -- Topics without [CODE] tags or a meaningful topic title, will be neglected by me (and probably many others as well) --

  • Re: Multi-button Input Form with on-the-fly userform


    Hi mike,


    I’m getting numerous Compile Errors when clicking on the “demo” button. Error is always “Can’t find project or library”


    Example:


    this code is highlighted in yellow


    Code
    1. Property Get InputForm(Prompt As String, _
    2. Optional Buttons As Variant, _
    3. Optional Title As String, _
    4. Optional Default As String, _
    5. Optional dataType As Long, _
    6. Optional PasswordChar As String) As Variant



    and the word Chr$ is selected in this line of code


    Code
    1. If CStr(PasswordChar) = "True" Then PasswordChar = Chr$(165)


    I get them with simple code such as where Left$ is selected:


    Code
    1. PasswordChar = Left$(PasswordChar, 1)


    Removing the $ has no effect, same compile errors.


    I’m using xl2000 on the old dog windows98


    Any ideas?


    Bill

    [FONT="Arial Black"][COLOR="blue"][SIZE="4"]Bill[/SIZE][/COLOR][/FONT]
    Tip: To avoid chasing code always use Option Explicit.

  • Re: Multi-button Input Form with on-the-fly userform


    I get compile errors as well, with Chr$() and LTrim(). Yet when I unload the worksheet, both functions work in the Immediate window. And also on

    Code
    1. Dim Form as UserForm

    [SIZE=1]Entia non sunt multiplicanda sine necessitate.[/SIZE]

  • Re: Multi-button Input Form with on-the-fly userform


    The RefEdit library needs to be open as does the Microsoft Visual Basic for Applications Extensibility library.


    I've found another problem. Every time a userform is created and destroyed, the file takes up a little more space. Excel doesn't complely clear all the memory when a userform is deleted. A temporary userform will make a file grow with each use. A version with permenant userform would be better.

  • Re: Multi-button Input Form with on-the-fly userform


    mike,


    Quote

    The RefEdit library needs to be open as does the Microsoft Visual Basic for Applications Extensibility library.


    I now have these libraries referenced and got past the initial compile errors. Now have a compile error “Expected user-defined type, not project.”




    Code
    1. Private Sub makeRawForm(newComp As Object, _
    2. Prompt As String, _
    3. ByVal Buttons As Long, _
    4. Title As String, _
    5. Default As String, _
    6. PasswordChar As String)
    7. Dim newForm As UserForm
    8. Dim refEditBox As RefEdit ‘ <<< This line gives the error


    Bill

    [FONT="Arial Black"][COLOR="blue"][SIZE="4"]Bill[/SIZE][/COLOR][/FONT]
    Tip: To avoid chasing code always use Option Explicit.