Page 2 of 2 FirstFirst 12
Results 16 to 23 of 23
  1. #16
    New Lounger
    Join Date
    Mar 2014
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Paul for looking at my fiasco,

    I tried different avenues to get this to work as you can see from the existing codes and the userform. I originally used bookmarks to update the fields in the document but it did not work correctly. I commented off some of my previous trials that obvious did not work right to try new ideas but still did not work.

    Could you try to get it to work correctly whether it is through DOCPROPERTY, BOOKMARKS, OR whatever means using the user form to update the document?

    Thanks Paul

  2. #17
    New Lounger
    Join Date
    Mar 2014
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Andrew has different thoughts on how to do this. He previous give me some Ideas. Thanks to you all guys.

  3. #18
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,767
    Thanks
    0
    Thanked 162 Times in 150 Posts
    Quote Originally Posted by khufu View Post
    Could you try to get it to work correctly whether it is through DOCPROPERTY, BOOKMARKS, OR whatever means using the user form to update the document?
    I've already told you exactly what you need to do to get this working with DOCPROPERTY. See my last post. Sure, I could do it for you but you wouldn't learn much from that.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  4. #19
    New Lounger
    Join Date
    Mar 2014
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey Andrew I uploaded a copy of the document.

    Thanks

  5. #20
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,429
    Thanks
    3
    Thanked 124 Times in 117 Posts
    Since your sample document is using more specialised fields than the common built-in document properties I have done a few content controls and linked them to a custom xml file. This attached document should provide an indication of how this would work.

    If this is what you want to use, you will probably want to use the Word Content Control Toolkit available from http://dbe.codeplex.com/

    There are links on that page to a tutorial which describes how to use the tool.
    Attached Files Attached Files
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  6. #21
    New Lounger
    Join Date
    Mar 2014
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey Andrew,
    Thanks for the insight. What I am trying to do is input the information from the useform and once I hit submit, the information will be inserted into the document. Originally I was using the bookmarks until I stumble on you guys information on DOCPROPERTy. I don't know which is the best way to proceed but I am currently in a jungle of confusion. I find myself vacillating between choosing the best path and once I do, stick to it.

    So, as you see from the userform I already have what I want to be inserted. How is a different story. Please look at my userform and give my your take on how to proceed to achieve my objective. I need someone me thorough part of the way.

    Thank you very much.

  7. #22
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,429
    Thanks
    3
    Thanked 124 Times in 117 Posts
    Ahh. I hadn't gone looking for your UserForm. I see it now.

    OK, if you want to follow the userform pathway with either bookmarks or customdocproperties...

    The Submit button code is failing because you can't change the value of a custom property unless that custom property already exists. You can either pre-add the custom property field via the document's advanced properties dialog or you can do it with on the fly with code.
    Your code to fill the combo boxes is also in the wrong place. This code needs to be in the form's initialise macro which is called UserForm_Initialize.

    I have modified your userform code to resolve these issues to get you back on track
    Code:
    Private Sub cmdClear_Click()
       txtFirstName.Value = ""
       txtLastName.Value = ""
       txtSecurityDeposit.Value = ""
       txtStreetName.Value = ""
       cboCity.Value = ""
       cboState.Value = ""
       cboZip.Value = ""
       cboBedrooms.Value = ""
       cboBathrooms.Value = ""
       txtMonthlyRent.Value = ""
       txtYearlyRent.Value = ""
    End Sub
       
    Private Sub cmdSubmit_Click()
      WriteCustomProp "TodaysDate", Me.dtTodaysDate, msoPropertyTypeDate
      WriteCustomProp "FirstName", Me.txtFirstName, msoPropertyTypeString
      WriteCustomProp "LastName", Me.txtLastName, msoPropertyTypeString
      WriteCustomProp "SecurityDeposit", Me.txtSecurityDeposit, msoPropertyTypeString
      WriteCustomProp "StreetName", Me.txtStreetName, msoPropertyTypeString
      WriteCustomProp "City", Me.cboCity, msoPropertyTypeString
      WriteCustomProp "State", Me.cboState, msoPropertyTypeString
      WriteCustomProp "Zip", Me.cboZip, msoPropertyTypeString
      WriteCustomProp "Bedrooms", Me.cboBedrooms, msoPropertyTypeString
      WriteCustomProp "Bathrooms", Me.cboBathrooms, msoPropertyTypeString
      WriteCustomProp "StartDate", Me.dtStartDate, msoPropertyTypeDate
      WriteCustomProp "EndDate", Me.dtEndDate, msoPropertyTypeDate
      WriteCustomProp "MonthlyRent", Me.txtMonthlyRent, msoPropertyTypeNumber
      WriteCustomProp "YearlyRent", Me.txtYearlyRent, msoPropertyTypeNumber
      WriteCustomProp "MonthlyRent", Me.txtMonthlyRent, msoPropertyTypeString
      ActiveDocument.Fields.Update
      Unload Me
    End Sub
    
    Function WriteCustomProp(sProp As String, sValue As String, iType As Integer) As Boolean
      Dim prop As DocumentProperty, bExists As Boolean
      bExists = False
      For Each prop In ActiveDocument.CustomDocumentProperties
        If LCase(prop.Name) = LCase(sProp) Then
          bExists = True
          prop.Value = sValue
          Exit For
        End If
      Next
      If Not bExists Then
        ActiveDocument.CustomDocumentProperties.Add Name:=sProp, Value:=sValue, _
              LinkToContent:=False, Type:=iType
      End If
    End Function
    
    Private Sub cmdClose_Click()
      Unload Me
    End Sub
    
    
    Private Sub UserForm_Initialize()
      With cboBathrooms
        .AddItem "(1) one bathroom"
        .AddItem "(1½)One and one half bathrooms"
        .AddItem "(2)two bathrooms"
        .AddItem "(2½)two and one half bathrooms"
        .AddItem "(3)three bathrooms"
        .AddItem "(3½)three and one half bathrooms"
        .AddItem "(4)four bathrooms"
        .AddItem "(4½)four and one half bathrooms"
      End With
      
      With cboBedrooms
         .AddItem "(1) one bedroom"
         .AddItem "(2) two bedrooms"
         .AddItem "(3) three bedrooms"
         .AddItem "(4) four bedrooms"
         .AddItem "(5) five bedrooms"
         .AddItem "(6) six bedrooms"
      End With
      
      With cboZip
        .AddItem "19023"
        .AddItem "19143"
        .AddItem "19139"
        .AddItem "19131"
        .AddItem "19140"
        .AddItem "19145"
      End With
    
      With cboCity
        .AddItem "Philadelphia"
        .AddItem "Darby"
        .AddItem "Sharon Hill"
        .AddItem "Colwyn"
        .AddItem "Collingdale"
        .AddItem "Glenolden"
      End With
      
      With cboState
        .AddItem "Pennysalvania"
        .AddItem "Delaware"
        .AddItem "New Jersey"
        .AddItem "New York"
        .AddItem "Maryland"
      End With
    
    End Sub
    Once you run the code behind the submit button you would have the custom document properties saved so you can then place the fields into the document in each of the locations where needed. The field code would follow a pattern such as { DOCPROPERTY "Bathrooms" }
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  8. #23
    New Lounger
    Join Date
    Mar 2014
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey Andrew you are a God sent. I was walking though this dark room and could not see anything, your light gives the illumination that I needed. Thank you, thank you, thank you.

Page 2 of 2 FirstFirst 12

Posting Permissions

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