Results 1 to 15 of 15
  1. #1
    Star Lounger
    Join Date
    Jan 2008
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Saving and Reopening a doc while saving variables.

    My Template creates Docs with any number of the types of building-blocks that are added and deleted with buttons on the custom "ABC Report Toolbar".

    It keeps track of the total number of deeds, mortgages, assignments with variables in the vba code.

    This is how it knows what bookmark to start deleting from.

    This variable is reset when the doc is saved and reopened.

    Is there a way to have the add and deletes go off of numbered bookmark without keeping count?

    Would a For loop comparing the number at the end of each bookmark be an efficient way to get then number to start deleting or adding from, when a document is reopened?

    Any suggestions are welcome, thanks!
    Attached Files Attached Files

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

    Re: Saving and Reopening a doc while saving variables.

    You could store the number of deeds, mortgages etc. in document variables. These are saved with the document.
    For deeds:

    - Add the following line to the Document_New event procedure in the ThisDocument module:

    ActiveDocument.Variables("DeedCount") = 0

    - Use ActiveDocument.Variables("DeedCount") instead of the global variable d, for example:

    ActiveDocument.Variables("DeedCount") = ActiveDocument.Variables("DeedCount") + 1
    .Bookmarks.Add Name:="DeedRecord" & ActiveDocument.Variables("DeedCount"), Range:=myRange

    Similarly for mortgages etc.

  3. #3
    Star Lounger
    Join Date
    Jan 2008
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Saving and Reopening a doc while saving variables.

    Thanks!

  4. #4
    Star Lounger
    Join Date
    Jan 2008
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Saving and Reopening a doc while saving variables.

    This is odd. Now when I use the "+ Deed" button the very first deed doesn't get bookmarked "DeedRecord1" anymore. The bookmark with "NoNewDeedFilings", which is supposed to simply hide when deeds are added, is now split in two, between the first deed added and the hidden text at the end of the deeds section.

    When I use the "- Deed" button it fails on what should be "DeedRecord1" because it isn't bookmarked. (I can't understand why, as all I did was change the counter-variable to the New Document module)

    ...OK... now I see it happens when the second deed is added. When the first deed is added it *IS* bookmarked "DeedRecord1". I am totally stumped.

    Any ideas?
    Attached Files Attached Files

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

    Re: Saving and Reopening a doc while saving variables.

    When I click +Deed, the DeedRecord1 bookmark is duly created, so the -Deed button works too. But the bookmark is created within the NoNewDeedFilings bookmark, so you should move the range where you insert the deed bookmark outside of the range of the NoNewDeedFilings bookmark.

  6. #6
    Star Lounger
    Join Date
    Jan 2008
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Saving and Reopening a doc while saving variables.

    Hans,

    I believe it used to create "DeedRecord1", "DeedRecord2" etc. within the "NoNewDeedFilings" bookmark as it does now. (it deleted bookmarks within a bookmark as the deeds were removed, but when they were all gone, the contents of "NoNewDeedFilings" was the same as before they were added)

    Now the "DeedRecord1" bookmark is deleted as the 2nd deed is added, but no code other than the variable has changed.

    It doesn't remove the "DeedRecord2" bookmark when a third deed is added, and so forth, so since this only happens to the first deed, could it be something wrong with the condition testing if "DeedCount" = 0?

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

    Re: Saving and Reopening a doc while saving variables.

    The AutoText entry named DeedRecord includes a bookmark named DeedRecord1, so each time you insert this AutoText entry, you effectively delete the existing bookmark named DeedRecord1.
    You should save the AutoText entry in the template without a bookmark DeedRecord1.

  8. #8
    Star Lounger
    Join Date
    Jan 2008
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Saving and Reopening a doc while saving variables.

    aha. thanks so much!

    I need to set the default tax year in a drop down-form field "TaxYearDropDown" based on the state selected in the drop-down form field "myState". Do you know how this could be done with an If or Case statement, that will change as the user changes the state selection? Will i need to switch the dropdown to a combo-box, like the report title?

    I am guessing this code isn't even close, I am sure I can figure out how to switch the drop-down to a combo box created in each document based on the template.

    I probably just need to know how to switch the year in TaxYearDropDown after a condition is met.

    If myState = "Indiana" Then
    TaxYearDropDown = "2006"
    End If

    If myState = "Florida" Then
    TaxYearDropDown = "2007"
    End If

    etc...

    Thanks in advance

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

    Re: Saving and Reopening a doc while saving variables.

    You could create a macro like this:

    Sub SelectState()
    With ActiveDocument
    Select Case .FormFields("SelectStateDropDown").Result
    Case "FL", "OH"
    .FormFields("TaxYearDropDown").Result = "2006"
    Case "IN"
    .FormFields("TaxYearDropDown").Result = "2007"
    End Select
    End With
    End Sub

    and set it as the On Exit macro for the SelectStateDropDown form field.

  10. #10
    Star Lounger
    Join Date
    Jan 2008
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Saving and Reopening a doc while saving variables.

    Thanks a bunch. That works.

    I changed "SelectState" to a combo box because a dropdown apparently requires the use of the mouse (I can't get it to work with the up and down arrows), and if the user clicks on the next field with the mouse instead of tabbing out of the state field, the sub isn't activated.

    As a combo box, the problem is formatting. The SelectState combobox hangs out far to the right and up, no matter how I seem to change the properties.

    Does a dropdown field NEED to be used to have the text line up seemlessly?
    Attached Files Attached Files

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

    Re: Saving and Reopening a doc while saving variables.

    You could remove the space before the combo box, and lower it by 3 or 4 points in the Character Spacing tab of the Format | Font... dialog.
    I found the combo box very confusing since you don't display a dropdown arrow. I'd set the ShowDropButtonWhen property to 1 - fmShowDropButtonWhenFocus.

  12. #12
    Star Lounger
    Join Date
    Jan 2008
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Saving and Reopening a doc while saving variables.

    Hans, I put the drop-down arrow back, but the formatting problem remains. It seems that the outer shell of the combo-box increases the height of the line it is on unless I turn off "auto-size", in which case I can only get the combo box to sort-of line up correctly if it is too small to show the entire height of the line of text in it. (This still raises the contents of the combo box above the line)

    Is there something from the controls toolbar that fits in seemlessly like the drop-down form field? Would a list-box, scroll-bar, or something else allow the user to select a state without creating a gap with the line above?

    If not, can I modify the prefs in the drop-down field to activate with arrow keys, and calculate as each drop-down selection is hit, like it works in the combo box?
    Attached Files Attached Files

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

    Re: Saving and Reopening a doc while saving variables.

    I already mentioned in my previous reply that you can lower the combo box by 3 or 4 points. This allows you to increase its height by the same amount, so that it can display the text correctly.

    A dropdown formfield only lets you react when the user leaves the formfield, not when the user selects an item.

  14. #14
    Star Lounger
    Join Date
    Jan 2008
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Saving and Reopening a doc while saving variables.

    I was able to raise the line to the left of the combo-box a few points and add paragraph spacing after the lines above, so they all have a gap. I never could get into the font properties of the combo-box independantly of the rest of the line. Ah-well. At least it lines up, if it takes up unnessessary space.

    now I can't add tax parcels: "The requested member of the collection does not exist." whenever "+ Parcel" is pressed.

    The variable "myState" is not getting the result from the Combo-box

    myState = ActiveDocument.FormFields("SelectState").Result

    Is this close to give the myState variable the contents of the SelectState Combo-box?
    Attached Files Attached Files

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

    Re: Saving and Reopening a doc while saving variables.

    If you want to change the font displayed in the SelectState combo box:
    - Unprotect the document.
    - Display the Control Toolbox.
    - Activate Design Mode (make sure that the first button on the Control Toolbox is "down").
    - Click the SelectState combo box to select it.
    - Click the Properties button on the Control Toolbox (the second button).
    - Click in the Font property.
    - Click the ... button in the Font property.

    SelectState is not a formfield but an OLE control, so obviously you cannot use the FormFields collection to retrieve its value. You can use

    myState = ActiveDocument.InlineShapes(1).OLEFormat.Object.Va lue

Posting Permissions

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