• Dialogs and form names (VBA Off2K/ Wd2K)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Dialogs and form names (VBA Off2K/ Wd2K)

    Author
    Topic
    #398207

    Hi

    Is it possible to send in a form name to a function in order to set a dialog as an object. (sounds odd, but pls. see example below)
    – this will enable me to re-use a single sub for a lot of various call types.

    Sub 1
    dim strFrmIs as string

    ‘here runs a lot of initial code
    ‘- then I need some user Input
    ‘after that I would like the Form name to be the identifier of which function that is calling – to avoid hard coding names.

    strFrmIs=frm.Name
    Sub 3 strFrmIs

    End sub

    ‘***************************************
    Sub 2
    dim strFrmIs as string

    strFrmIsr=frm.Name
    Sub3 strFrmIs

    End sub

    ‘*************************************’

    Sub 3(frmName as string)

    set ThisDlg = (frmName)

    frmName.show

    “bla.bla.bla.bla”

    End sub

    Viewing 2 reply threads
    Author
    Replies
    • #759549

      If you are doing this in Word VBA, recommend look at the Word Application object Run method. According to VBA Help, this method “Runs a Visual Basic macro” where the first arg is MacroName: “Required String. The name of the macro. Can be any combination of template, module, and macro name. ” See VBA Help for Run Method for more info & examples of how to use.

      HTH

      • #759561

        Hi and thanks,

        What I was hoping for was an equivalent to the MS built-in .dialogs(“xx”).
        Just hoping that this existed for user forms.

        Guess not – pity

        .run method will be to much of a de-tour.

        • #759669

          You might be able to use the form’s name as an index into a UserForms collection. Is there such a collection natively, or does it only exist in the VBA Extensibility library? Hmmm… (off playing)

          No, actually this looks rather bleak. First, you need to initialize UserForm objects for each form before they will be found in the UserForms collection. Then, the UserForm object does not appear to have any Name that you could use as an index. Also, I’m getting a blank string back for the .Caption property. I get security errors attempting to sneak in through the VBA Extensibility library’s VBComponents collection. So… hardcoding still appears to be the way to go.

        • #759670

          You might be able to use the form’s name as an index into a UserForms collection. Is there such a collection natively, or does it only exist in the VBA Extensibility library? Hmmm… (off playing)

          No, actually this looks rather bleak. First, you need to initialize UserForm objects for each form before they will be found in the UserForms collection. Then, the UserForm object does not appear to have any Name that you could use as an index. Also, I’m getting a blank string back for the .Caption property. I get security errors attempting to sneak in through the VBA Extensibility library’s VBComponents collection. So… hardcoding still appears to be the way to go.

      • #759562

        Hi and thanks,

        What I was hoping for was an equivalent to the MS built-in .dialogs(“xx”).
        Just hoping that this existed for user forms.

        Guess not – pity

        .run method will be to much of a de-tour.

    • #759550

      If you are doing this in Word VBA, recommend look at the Word Application object Run method. According to VBA Help, this method “Runs a Visual Basic macro” where the first arg is MacroName: “Required String. The name of the macro. Can be any combination of template, module, and macro name. ” See VBA Help for Run Method for more info & examples of how to use.

      HTH

    • #760608

      This is off the wall perhaps, but in Access or VB, I would just pass the object itself, rather than its name alone. Then all you have to do is use the passed object and you never really have to know its name.

    Viewing 2 reply threads
    Reply To: Dialogs and form names (VBA Off2K/ Wd2K)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: