Consulting

Results 1 to 5 of 5

Thread: Solved: Trying to work out which userform has been opened

  1. #1
    VBAX Contributor Glaswegian's Avatar
    Joined
    Sep 2004
    Location
    Glasgow, Scotland
    Posts
    196
    Location

    Solved: Trying to work out which userform has been opened

    Hi all

    I'm not sure if I'm going about this the right way, but at the moment I'm stuck.

    I have a workbook with various forms. The forms are accessed by choosing a specific command button on the one visible sheet. Data is input to the form, and once complete users click a button on the form. This then opens another form that allows users various save/cancel options via a series of option buttons The original input form remains visible until the save/cancel operation is complete. All forms are modal.

    To avoid data going to the wrong sheet, I'd like to be able to find out which form has been used for input. I can then check this against the option button selected.

    At the moment, I write the original form name to a hidden sheet - I know the name because each button opens a specific form.

    What I can't work out is how to use this name with the save/cancel form. For example
    If opt1 = True Then
        DataToHolding
        Me.Hide
        frmMain.Hide
    End If
        If opt2 = True Then
            DataToData
            Me.Hide
            VBA.UserForms.Item(cForm).Hide
    '.....................and so on......
    Data is written to the relevant sheet, the save/cancel form is then hidden and I would then like to check the original form used, but the "VBA.UserForms" part is the nearest I can get. - and of course I receive a 'type mismatch' error.

    I would appreciate any suggestions
    Iain - XL2010 on Windows 7

  2. #2
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    This will return the name of the most recently opened userform
    [VBA]MsgBox UserForms(UserForms.Count - 1).Name[/VBA]

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    If you have the name, then don't you know which one.

    I am not understanding what that code sample is doing, where it is called from.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    VBAX Contributor Glaswegian's Avatar
    Joined
    Sep 2004
    Location
    Glasgow, Scotland
    Posts
    196
    Location
    Hi

    Mike - that was the code I was looking for! A quick tweak to -2 returns the name of the form prior to save/cancel form (which will always be the last form opened).

    Many thanks.
    Iain - XL2010 on Windows 7

  5. #5
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    You're welcome

Posting Permissions

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