Results 1 to 7 of 7
  1. #1
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Userforms calling userforms (Outlook XP+)

    My good friend <!profile=Rory>Rory<!/profile> has dragged me unwillingly into userforms in <!post=this thread,311485>this thread<!/post>. (If anyone does heavy attachment processing in Outlook they may want to play with the form Rory developed and I heavily hacked in that thread.)

    In the currently posted version, when a user tries to save an attachment to disk and a file of the same name already exists in the target folder, a vast cascade of dialog boxes can ensue, depending on the users choices. Well, OK, up to four dialogs.

    My intention now is to replace those cascading dialogs with just one userform. I have the form laid out, but I haven't developed userforms, so I'm up the proverbial creek without a compass. So here I go with some dumb questions:

    1. Can a userform call another userform? If so how? My efforts so far, even with the parameter references commented out, lock up Outlook. Just the frame of the ChildUserform appears. Both forms are set as not modal. The calling function in ParentUserform is:

    Public strSaveName as String
    Public bytDupFile3State as Byte
    ' if 0, att file is skipped completely
    ' if 1, the att file is (over)written to disk
    ' if 2 the att file name is written to the Item Body but not saved to disk

    Private Sub dupcheck()
    bytDupFile3State = 0
    If Len(Dir(strSaveName, vbDirectory)) = 0 Then
    bytDupFile3State = 1
    Else
    bytDupFile3State = 1
    Do
    frmDupFName.Show
    Loop Until Len(Dir(strSaveName, vbDirectory)) = 0 Or bytDupFile3State <> 1
    End If
    End Sub

    2. And also if so, can parameters be passed back and forth as arguments, or set by settiing certain ParentUserform variables as Public as I did above? At this time I need the strFilename passed back and forth from, ParentUserform to frmDupFName, or changed by frmDupFName, and I need bytDupFile3State, which can be changed by user selection in the called frmDupFName, available to the ParentUserform.

    I have Googled about and searched this Forum but haven't found this kind of information. Any good soup-to-nuts userform sites on the net, or textbooks someone can recommend?
    -John ... I float in liquid gardens
    UTC -7ąDS

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Userforms calling userforms (Outlook XP+)

    1. Yes, you can open one userform from another, but opening the same userform several times in a loop

    Do
    frmDupFName.Show
    Loop Until ...

    is not very useful if the form is non-modal.

    2. You can load a userform into memory, set the value of variables defined as public in the form module and/or the value of controls on the userform, then display the userform:

    Load UserForm2
    With UserForm2
    .TextBox1.Text = "Hello World"
    .Show
    End With

    If a form isn't displayed properly, this usually means that your code is busy doing other things. You can force the display to be updated with

    UserForm2.Repaint

    and if you're executing a loop, inserting DoEvents gives other events (such as window redraw events) a chance.

  3. #3
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Userforms calling userforms (Outlook XP+)

    Thanks, Hans. I took all of your advice (to the extent I understood it) to heart and the form doesn't lock up, but ...

    the two Public variables I want to call and modify in the Child Userform are declared in the Parent Userform. They are not being recognized as explicit variables in the Child userform. Do I have to declare the Public variables in a general Module, or is there some other way I should be declaring them? (Should I attach it all as Zip file?)

    Also, can you clarify that OnEvents can be set as a no-parameter, no-argument, statement after a call to the System. I do have such a call so I'm just using:

    txtPath = _
    Replace(CreateObject("Shell.Application").BrowseFo rFolder(0, _
    "Select Folder for saving selected files", 0, 17).Items.Item.Path & "", "", "")
    DoEvents
    Me.Repaint

    Is that how to use it?
    -John ... I float in liquid gardens
    UTC -7ąDS

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Userforms calling userforms (Outlook XP+)

    If the parent form is open, the child form can get at variables declared as public in the parent form module, but you must use them like this: UserForm1.VariableName, not just VariableName.

    Do you mean DoEvents in your second question? I've never heard of OnEvents. DoEvents can be inserted wherever you want to give other processes a chance to do something. It has no arguments.

  5. #5
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Userforms calling userforms (Outlook XP+)

    Thanks, I get it on the Variables.

    And yes, I meant DoEvents, I used it correctly in the code, but misstated it in the Post text.
    -John ... I float in liquid gardens
    UTC -7ąDS

  6. #6
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Userforms calling userforms (Outlook XP+)

    John,
    You can't blame me - you're the one who suggested a userform in the first place! <img src=/S/grin.gif border=0 alt=grin width=15 height=15>
    If you want to post it as a Zip file, we can get started on phase 2 (of about 36 I guess...).
    Regards,
    Rory

    Microsoft MVP - Excel

  7. #7
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Userforms calling userforms (Outlook XP+)

    I did? <img src=/S/innocent.gif border=0 alt=innocent width=20 height=20> I wondered when you'd see my little jab at you! <img src=/S/laugh.gif border=0 alt=laugh width=15 height=15> Sometimes we seek to learn, and sometimes we have learning thrust upon us! <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15> <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

    Thanks to Hans' advice, I now have the duplicate handler working really well. However I've concluded that I need to restore the Save and Close buttons you had on the original userform design (and their functionality), while still having the Browse button perform an automatic Save, and do a couple more error-handling thingies, and I'll post the new forms to the Outlook Thread.

    Fortunately I'm on interminable teleconferences, so I have time to do some of this!
    -John ... I float in liquid gardens
    UTC -7ąDS

Posting Permissions

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