Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Denmark
    Posts
    347
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Dialogs and form names (VBA Off2K/ Wd2K)

    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
    Bests,
    RD


    PS: Wish there were a knob on the TV to turn up the intelligence. There's a knob called "brightness," but that doesn't work

  2. #2
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Dialogs and form names (VBA Off2K/ Wd2K)

    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

  3. #3
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Denmark
    Posts
    347
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Dialogs and form names (VBA Off2K/ Wd2K)

    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.
    Bests,
    RD


    PS: Wish there were a knob on the TV to turn up the intelligence. There's a knob called "brightness," but that doesn't work

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Dialogs and form names (VBA Off2K/ Wd2K)

    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.

  5. #5
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Dialogs and form names (VBA Off2K/ Wd2K)

    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.
    Charlotte

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •