Consulting

Results 1 to 8 of 8

Thread: Reloading Userform after initial submission

  1. #1
    VBAX Regular
    Joined
    May 2015
    Posts
    44
    Location

    Reloading Userform after initial submission

    Hi all,

    I wondered if it was possible to reload or bring back a Userform once it has already been used.

    For example, a Userform to create a letter might populate bookmarked sections of the letter with the text inputted into the various TextBoxes in the Userform. Often once the user has completed the Userform they press 'Submit' or 'OK' via a commandbutton, the letter is generated with the information selected / inputted in the Userform and the Userform is hidden.

    However, where the user then notices mistakes or wants to make changes for whatever reason, would it be possible to 'reload' the previous Userform (with the users previously selected/inputted information) so that it could be altered and then resubmitted? The point being that much of the previous information will be fine and only a handful of things may need to be changed, so keeping the previous information to be amended in the Userform would save the user time rather than re-inputting good information.

    I imagine if this is possible, it would potentially require the initial round of changes made by the first submission of the Userform to be undone?

    Any thoughts would be great!

    Thanks,
    AJHEZ

  2. #2
    VBAX Regular
    Joined
    May 2015
    Posts
    44
    Location
    I probably should include that I start the Userform upon opening a new document with:

    [VBA]
    Private Sub Document_New()
    UserForm1.Show
    End Sub
    [/VBA]

    And once the User decided to submit the Userform by pressing the commandbutton after the various code to deal with the inputting, I use:

    [VBA]
    UserForm1.Hide
    [/VBA]

  3. #3
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,340
    Location
    Have you tried Userform1.Show?

    Edited: Sorry it seems I didn't fully read you post/question. I describe your situation as needing and interactive userform. See:
    http://gregmaxey.mvps.org/word_tip_p...userforms.html
    Last edited by gmaxey; 05-26-2015 at 04:41 AM.
    Greg

    Visit my website: http://gregmaxey.com

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    Inside Document_Open() you could read the Bookmarked data into the UF controls, allow the user to make changes and an [Update] or [Discard] option
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  5. #5
    At its most basic - lets assume a userform with three text boxes and a command button. Add the following to an ordinary module in the template. This will look at the bookmarks in the document and will fill the named form text boxes with the values of the three named bookmarks. When the command button is clicked the text box values are written back to the bookmarks.

    Option Explicit
    
    Sub ProcessForm()
    Dim ofrm As New UserForm1
    Dim oBm As Bookmark
        With ofrm
            For Each oBm In ActiveDocument.Bookmarks
                Select Case oBm.Name
                    Case "bm1": .TextBox1.Text = oBm.Range.Text
                    Case "bm2": .TextBox2.Text = oBm.Range.Text
                    Case "bm3": .TextBox3.Text = oBm.Range.Text
                End Select
            Next oBm
            .Show
            If .Tag = 1 Then
                FillBM "bm1", .TextBox1.Text
                FillBM "bm2", .TextBox2.Text
                FillBM "bm3", .TextBox3.Text
            End If
        End With
        Unload ofrm
    lbl_Exit:
        Set ofrm = Nothing
        Set oBm = Nothing
        Exit Sub
    End Sub
    
    Private Sub FillBM(strBMName As String, strValue As String)
    Dim oRng As Range
        With ActiveDocument
            On Error GoTo lbl_Exit
            Set oRng = .Bookmarks(strBMName).Range
            oRng.Text = strValue
            oRng.Bookmarks.Add strBMName
        End With
    lbl_Exit:
        Set oRng = Nothing
        Exit Sub
    End Sub
    The command button code will be

    Private Sub CommandButton1_Click()
        Me.Hide
        Me.Tag = 1
    lbl_Exit:
        Exit Sub
    End Sub
    You can call the main macro 'ProcessForm' from both a Document_Open and a Document_New macro (and a button on the QAT or ribbon also if you wish).
    If the bookmarks don't exist nothing will happen to the document or form in respect of the missing bookmark(s).
    Attached Files Attached Files
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  6. #6
    VBAX Regular
    Joined
    May 2015
    Posts
    44
    Location
    I had tried UserForm1.Show, but this didnt appear to do anything at all.

    I will take a look at gmayors idea and give it a whirl - I have a huge amount of textboxes in the userform so i'll need to knuckle down to get through it all.

    Cheers for the suggestions as always!

  7. #7
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    You might try a UserForm2, with just a CommandButton and sized to fit the CBut. The CBut Form must have its ShowModal Property set to False so the User can interact with the document as needed.

    Use the CBut form's Terminate Event Or use two buttons to actually submit the document, and UserForm1's "Submit" button to show the CBut form and display the new Doc.

    In the attached SamTexample.doc, run the Macro "TestSamT." Input some text in the TextBox on the Form that Shows, then click the CBut.
    Attached Files Attached Files
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  8. #8
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,340
    Location
    Greg

    Visit my website: http://gregmaxey.com

Posting Permissions

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