Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    New Lounger
    Join Date
    Mar 2002
    Location
    TX
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Userform variables (Word 97)

    here must be something I'm missing here. I can get my Userform to load, show, and hide. All attempts to get the form to retrieve, display, and update variables referring to a set of document properties have failed. Here's what I have coded:

    Sub UserForm_Initialize()

    Dim form1 As UserForm
    Dim boxAuthor
    Set form1 = formDocumentProperties

    'set initial values for each text box
    form1.boxAuthor.Value = ActiveDocument.BuiltInDocumentProperties(wdAuthor) .Value

    End sub

    ===

    Here's the code in This Document:

    Private Sub Document_Open()


    Dim formDocumentProperties As UserForm
    Dim form1
    Dim boxAuthor, boxDesc, boxDocID
    Dim boxDocTitle, boxProgramProj, boxRevAuthor
    Dim boxVersion, chboxLastChanged

    Set form1 = New formDocumentProperties

    'initialize and load values for fields
    Load form1
    'display Document Properties UserForm
    form1.Show

    Please help, the project is overdue!
    Thanks,
    LeAnne

  2. #2
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Userform variables (Word 97)

    LeAnne,

    Without taking the time to reproduce your situation and try to track down exactly what's not working, it does look like you're doing a whole lot of unnecessary assigning of object variables with regard to the userform.

    In the Document_Open procedure, do not declare a userform variable, and do not set the variable to formDocumentProperties - both are completely unnecessary.
    You can even dispense with the Load statement, and simply load it and show it in one go:

    formDocumentProperties.Show

    In UserForm_Initialize, do not declare the two variables and do not set the userform variable.

    You should be able to use syntax simply like:

    boxAuthor.Value = ActiveDocument etc.

    One other thought - you are declaring a 'boxAuthor' variable, and then referring to boxAuthor as a member of form1 a bit later - that could be causing a problem as well.

    Hope this helps,
    Gary

  3. #3
    New Lounger
    Join Date
    Mar 2002
    Location
    TX
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Userform variables (Word 97)

    Here's the new code, which produces an Error Message "5", Invalid Procedure Call or Argument

    Sub UserForm_Initialize()

    'set initial values for each text box

    boxVersion = ActiveDocument.CustomDocumentProperties(wdDocVersi on).Value

    End Sub

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Userform variables (Word 97)

    (1) This style is simpler. Actually, the Me isn't necessary, but it speeds the typing of the all the field names and minimizes typos.

    Sub UserForm_Initialize()
    'set initial values for each text box
    Me.boxAuthor.Value = ActiveDocument.BuiltInDocumentProperties(wdAuthor) .Value
    ...
    End sub

    (2) The valid constants for the built in properties are:

    <table border=1><td>wdPropertyAppName
    wdPropertyAuthor
    wdPropertyBytes
    wdPropertyCategory
    wdPropertyCharacters
    wdPropertyCharsWSpaces*
    wdPropertyComments
    wdPropertyCompany
    wdPropertyFormat
    wdPropertyHiddenSlides</td><td>wdPropertyHyperlinkBase*
    wdPropertyKeywords
    wdPropertyLastAuthor
    wdPropertyLines
    wdPropertyManager
    wdPropertyMMClips
    wdPropertyNotes
    wdPropertyPages
    wdPropertyParas
    wdPropertyRevision</td><td>wdPropertySecurity
    wdPropertySlides
    wdPropertySubject
    wdPropertyTemplate
    wdPropertyTimeCreated
    wdPropertyTimeLastPrinted*
    wdPropertyTimeLastSaved
    wdPropertyTitle
    wdPropertyVBATotalEdit
    wdPropertyWords</td></table>
    (3) For a custom property, the index usually is a string. The "5" error means that the property name was not found in the collection, so use quotation marks around your property name and check your spelling.

    Hope this helps. And next time, ask for help before the deadline. <img src=/S/wink.gif border=0 alt=wink width=15 height=15>

  5. #5
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Userform variables (Word 97)

    HI again,

    In your first post, you were referring to a Builtin property, so you could properly use a constant like "wdAuthor".

    In this example though, you're referring to a custom document property, so you cannot refer to it as if it were a built-in Word constant.
    If for instance you have a custom document property called "DocVersion", then your code would need to be:

    boxVersion = ActiveDocument.CustomDocumentProperties("DocVersio n").Value

    If you're still stuck, perhaps you can post a stripped-down version of the problem document and we can take a look.

    Gary

  6. #6
    New Lounger
    Join Date
    Mar 2002
    Location
    TX
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Userform variables (Word 97)

    thanks to both of you for your great help. In the meantime, we discovered that you can refer to both custom and built-in document properties by index number, as in ActiveDocument.CustomDocumentProperty(1). Value, which returns the value of the first property in the custom list, and ActiveDocument.BuiltinDocumentProperty(1).Value, which returns the value of Title.

    Note: Inside the Events (such as After Change), the .Value won't work. Event syntax is ActiveDocument... = Me.[variablename]

    Again, thanks so much!

  7. #7
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Userform variables (Word 97)

    Referring to a custom document property by index, rather than by name, will work - until the day a user deletes one of the custom document properties from a document. <img src=/S/grin.gif border=0 alt=grin width=15 height=15> Safer to use the name (and perhaps preceded by a call to an 'Exists' function as well).

    Gary

  8. #8
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Userform variables (Word 97)

    Remember that old thread a year ago about communication variable data betwen templates , and how Word97/Application.Run can't pass parameters? I decided to write a DLL to support communication methods. In the process I discovered the factoid below, and on searching for CustomDocumentProperties prior to posting, came across your post. More to follow in a day or two .... Here.



    When I use the following code in my Word97/VBA Class module
    <pre> doc.CustomDocumentProperties.Delete Name:=strName
    </pre>


    I get " Run-time error '438' Object doesn't support this property or method. "



    When I use the following code in my Word97/VBA Class module
    <pre> doc.CustomDocumentProperties(strName).Delete
    </pre>


    It runs very well indeed, thank you.

    I had to migrate the code from a VB6 class module to determine this.

    When I migrated the new code back to VB6, it works well there.


    Word97/VBA Help file seem to be incomplete; they don't mention the Name property, either.

  9. #9
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Userform variables (Word 97)

    Hi Chris,

    It seems like there's plenty of inconsistency in terms of how methods are called in VBA; it seems like different teams built different parts of the object model and didn't care to communicate with each other, or more likely, one project manager preferred doing things one way, while another preferred doing them the other way.

    BTW regarding communicating variable data between templates, you will recall as well the more recent thread with the "set a reference to the global template" method - hope you get a chance to try this as it works well.

    Gary

  10. #10
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Userform variables (Word 97)

    > different teams built different parts]

    Either that or else the documentation team didn't come back from the pub after collecting their bonus cheques!


    > recent thread with the "set a reference to the global template"

    Yes, but I was hoping you'd spoon-feed me (grin). this and this seem to be the most relevant.

    In my copious free, I'm essaying with using Normal.dot as a vehicle for the properties.

  11. #11
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Userform variables (Word 97)

    Chris,

    Was referring to this one here.

    Gary

  12. #12
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Userform variables (Word 97)

    Ah, right; Thanks!

  13. #13
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Userform variables (Word 97)

    I found another one yesterday, but I can explain everything, honest .....


    <pre>frmReducer.Controls.Item(j).Value
    </pre>


    frmReducer is defined as type UserForm.

    I know that the item has a value - I can display it in a MsgBox - but when I type the period after (j) I don't get prompted with "Value" in the list of available methods and properties.

    This has to be because, at the time I'm typing ("compile time"), the VBE can't possibly know what type of a control it is. If the control is a TextBox, then it won't have a value. That makes sense to me.

    Pity though that VBE doesn't include a greyish entry ror "Value", telling me "This might be valid but I'm not sure .....".

  14. #14
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Userform variables (Word 97)

    Hi Chris,

    In this case I don't think it's an inconsistency, it's doing that because frmReducer was defined as type UserForm. Once it's declared as type UserForm, the only things you will see in the autocomplete list are generic members of the (generic) UserForm class - controls that are specific to frmReducer won't appear there.

    If you do need to define frmReducer as a type to begin with, try using:

    Dim frmReducer As frmReducer
    - that will type your object frmReducer to the class frmReducer, and all of the unique members of frmReducer will appear in the autocomplete list.

    Gary

  15. #15
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Userform variables (Word 97)

    > frmReducer was defined as type UserForm

    Thanks and all, but also "eh?".

    It is a User Form. I'm expecting to see the AutoComplete (thanks for reminding me that it has a name!) coming off Item, and so I expect AutoComplete to tell me that an Item (of a Control) has a value.



    >Dim frmReducer As frmReducer

    I didn't think this was going to work even before I tried it, but <pre>Dim frmNew As frmReducer</pre>

    didn't work either. I think that you meant to type something else?



    I still feel that my explanation is closer to the mark. You and I know, as we type "Controls" that at this point in the code, the Control that we are indexing is going to be a TextBox, and hence we know that the Control will have a Value. The VBA syntax-checker and AutoCompleter et al. can't possibly know that yet. How could they know that the Control will be a TextBox, and not a Label. A label doesn't have a Value.

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
  •