Page 1 of 2 12 LastLast
Results 1 to 15 of 24
  1. #1
    4 Star Lounger
    Join Date
    Apr 2002
    Location
    Northern Territory, Australia
    Posts
    471
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Userform - Show contents on reopening document (Word 97)

    I am back again with my userform. After showing it to potential users they informed me that they are often called away or interrupted while working on this document and save it to come back later and work on it. When the document is saved the contents of the the userform are unloaded. They want the contents of the userform to be present when they reopen the document.

    How do I do this?

    Kerry
    Attached Files Attached Files

  2. #2
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Userform - Show contents on reopening document (Word 97)

    Hi Kerry,

    You could create a CustomDocumentProperty (CDP) for each element in the userform and save the content / status of the elements in the appropriate CDP after the user clicks a button on the userform that unloads / hides that form.
    When (re)opening the file and calling the form again you could, in the form_Initialize routine, read the CDPs and populate the elements of the form with the saved content / status. (Of course you have to check first whether or not the CDPs exist.)

    Regards,
    Jan

  3. #3
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Userform - Show contents on reopening document (Word 97)

    Hi Kerry

    The problem you mention here stems from the form having to reinitialize, as you say. What you want is to reseed the form with the docvar values (minus the trailing spaces). Something like this should do it:<pre>Private Sub ReseedForm()
    'Reset form values in accordance with docvar values

    tbxOffenderName = RTrim(.Variables("varOffenderName").Value)
    tbxLastKnownAddress = RTrim(.Variables("varLastKnownAddress").Value)
    tbxDCSId = RTrim(.Variables("varDCSId").Value)
    tbxJISCheck = RTrim(.Variables("varJISCheck").Value)
    ' etc.
    ' You will also have to reset option button values, dropdown values etc.
    ' in accordance with their corresponding .Variables() values

    End Sub</pre>

    The way you have things set up, you'd need to call this when an existing document opens and ensure it wasn't called unless all docvars actually exist <img src=/S/ranton.gif border=0 alt=ranton width=66 height=37>stupid variable collections <img src=/S/rantoff.gif border=0 alt=rantoff width=66 height=37>. To avoid the tired old scenario of referring to non-existent docvars, I'd do a minor rewrite that goes something like this:

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

    Re: Userform - Show contents on reopening document (Word 97)

    Alan has already posted excellent advice. Since I was working on the same thing, I will post the code snippet I had - it may save you some typing:

    With ActiveDocument
    tbxOffenderName = Trim(.Variables("varOffenderName"))
    tbxLastKnownAddress = Trim(.Variables("varLastKnownAddress").Value)
    tbxDCSId = Trim(.Variables("varDCSId").Value)
    tbxJISCheck = Trim(.Variables("varJISCheck").Value)
    tbxSeq = Trim(.Variables("varSeq").Value)
    tbxDate1stNotice = Trim(.Variables("varDate1stNotice").Value)
    tbxDate2ndNotice = Trim(.Variables("varDate2ndNotice").Value)
    tbxAlternateAddress = Trim(.Variables("varAlternateAddress").Value)
    tbxCCC = Trim(.Variables("varCCC").Value)
    tbxCCOName = Trim(.Variables("varCCOName").Value)
    cboCourt = Trim(.Variables("varCourt").Value)
    tbxCourtFileNo = Trim(.Variables("varCourtFileNo").Value)
    tbxHrsCompleted = Trim(.Variables("varHrsCompleted").Value)
    tbxNumberofHrsOrdered = Trim(.Variables("varNumberofHrsOrdered").Value)
    tbxExpiryDate = Trim(.Variables("varExpiryDate").Value)
    tbxLastKnownAddress = Trim(.Variables("varLastKnownAddress").Value)
    tbxLocationofCourt = Trim(.Variables("varLocationofCourt").Value)
    Me.optOath1.Value = (Trim(.Variables("varOath1").Value) = "make oath and say")
    Me.optOath2.Value = (Trim(.Variables("varOath1").Value) = "Affirm")
    tbxOffence = Trim(.Variables("varOffence").Value)
    tbxPhone = Trim(.Variables("varPhone").Value)
    cboAddressTo = Trim(.Variables("varAddressTo").Value)
    tbxHrsOutstanding = Trim(.Variables("varHrsOutstanding"))
    tbxWarningLetter = Trim(.Variables("varWarningLetter").Value)
    tbxSuspensionLetter = Trim(.Variables("varSuspensionLetter").Value)
    End With

  5. #5
    4 Star Lounger
    Join Date
    Apr 2002
    Location
    Northern Territory, Australia
    Posts
    471
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Re: Userform - Show contents on reopening document (Word 97)

    Hi Alan

    Wow! too much information! I am having a head spin. Can you show me how this works in my example please?

    Kerry

  6. #6
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Userform - Show contents on reopening document (Word 97)

    Hi Kerry

    Before I go further, is it your intention to have values pre-assigned to your document variables, when the user creates a brand new document? As it stands, your template itself contains the variables shown in the attachment, and these will become the "defaults" for new documents. This may be your intention, and quite a reasonable approach, but I want to first be sure that this is what you're after.

    Alan
    Attached Images Attached Images

  7. #7
    4 Star Lounger
    Join Date
    Apr 2002
    Location
    Northern Territory, Australia
    Posts
    471
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Re: Userform - Show contents on reopening document (Word 97)

    I did deliberately put in some values to into the template. It is not entirely necessary. It was just a way to show that there is actually a variable present.

    I am not concerned that there be values in a Brand New document, only a reopened document.

    Hope that makes sense.

    Kerry

  8. #8
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Userform - Show contents on reopening document (Word 97)

    I think it's a good idea from the standpoint of the new user. They get to see a "sample" document rather than just an empty framework, which is obviously "friendlier". I can't see where you initialized these values from code though. If they're just a legacy from previous work on the template, I'd suggest not relying on this "method"; rather, setting them up explicitly in the Document_New() procedure. To do this, you should firstly delete all docvars, then add them as you'd like them to display initially in the document. You might want to stick with "Fred Bloggs " or you might go for something more explanatory like "Full Name will appears here. "

    Your choice, but the important thing is to bring them all into existence by giving them a value you want at the outset. I'll have a go at your template on this basis and post it up. I might also take Hans' advice and "borrow" his code to save me some typing. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

    Alan

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

    Re: Userform - Show contents on reopening document (Word 97)

    Be my guest! <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

  10. #10
    4 Star Lounger
    Join Date
    Apr 2002
    Location
    Northern Territory, Australia
    Posts
    471
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Re: Userform - Show contents on reopening document (Word 97)

    I agree that some sample data is friendlier. What I did was put in "Offender Name" (not Fred Bloggs)in the offender name box, "DCS ID" in the DCS Id box and so on. This then gave the user an idea where their data would sit in the document if they chose to look before filling out the user form.

    I did this by opening the template, putting in the text, then commit changes and save. Then when I opened up a new blank document there was already some data in the actual document, but NOT in the user form. I dont want the user to have to delete text in the userform before entering their own.

    I am sorry if this is difficult to understand. Sometimes I wish I could "speak" my question <img src=/S/chatter.gif border=0 alt=chatter width=38 height=16> . Committing it to type is obviously not my talent. It must be a left brain, right brain thing! <img src=/S/dizzy.gif border=0 alt=dizzy width=15 height=15>

    Hans - thanks also for your help.

    Kerry

  11. #11
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Userform - Show contents on reopening document (Word 97)

    OK, I jumped a few steps ahead before I read your reply, so what's attached may not do it for you exactly as you want, but would be easily modified to do so. The form does show some data initially (not what you want) but as the user tabs from field to field, this data is selected, ready for typeover. Or you could have it totally empty for a brand new doc... whatever your choice. Another minor mod was to allow the user the use of the Enter key to start a new line in the multiline "address" textbox.

    This might have some small bugs too, as well as the functional shortcomings, but I think the general idea you're after has been implemented. Give it a shot creating & saving a new doc, then reopening it, and you'll see the form filled with the existing values.

    Alan
    Attached Files Attached Files

  12. #12
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Userform - Show contents on reopening document (Word 97)

    Thanks Hans... and I'm glad I did. When I copy/ pasted your code, all the linebreaks appeared correctly in the VBE. When I try this with the code I have posted to the lounge, all the linebreaks have vanished? What's your secret?... or is that a MVP thing? <img src=/S/wink.gif border=0 alt=wink width=15 height=15>

    Alan

  13. #13
    4 Star Lounger
    Join Date
    Apr 2002
    Location
    Northern Territory, Australia
    Posts
    471
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Re: Userform - Show contents on reopening document (Word 97)

    Alan it seems to function well. The only thing I would like (but can live with if not possible) is for a new doc to have the docvars filled but not on the userform. Is it possible to have one and not the other?

    Kerry

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

    Re: Userform - Show contents on reopening document (Word 97)

    Alan,

    It's no secret at all.

    You used the <!t>[pre]<!/t> and <!t>[/pre]<!/t> tags to post code. The advantage is that this preserves indentation, the disadvantage is that if you copy and paste directly into the VB Editor, you get one long line. The remedy is to paste into Word first and copy again; you can then safely paste into the VB Editor.

    I used <!t>[tab]<!/t> tags to replace multiple spaces by tabs. For very short snippets of code, I put them in manually, but for longer code fragments, I copy the code into Word, and run a little macro (I have posted it before, I think, but here goes):

    Sub Spaces2Tabs()
    On Error GoTo Err_Sub
    With Selection.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Execute FindText:=Space(4), ReplaceWith:="<!t>[tab]<!/t>", Replace:=wdReplaceAll
    End With
    Exit Sub
    Err_Sub:
    If Err <> 91 Then
    MsgBox Err.Description, vbExclamation
    End If
    End Sub

    Replace the 4 in Space(4) by whatever the number of spaces you use as Tab Width in the VB Editor.

  15. #15
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Userform - Show contents on reopening document (Word 97)

    Quite possible to do this, but I omitted it because its implementation would depend on your specific requirements. For instance, how would you want the userform to reappear after the following scenarios:

Page 1 of 2 12 LastLast

Posting Permissions

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