Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

User defined error on document property

Status
Not open for further replies.

ycim

Programmer
Feb 9, 2005
95
CA
I am trying to manipulate Word from my Access application. I need to add some customdocumentproperties, but when I try to declare the following

Code:
Dim itmDocProp As DocumentProperty

I get the following error

User defined type not defined

I am sure that this is simply a problem with the reference, but I have no idea which one. Can anyone point me in the right direction?

Thanks!
 
Could you please state how you are making, and using the instance of Word?

It may be as simple as:
Code:
Dim itmDocProp As [COLOR=red][b]Word[/b][/color red].DocumentProperty

Also, if it is a custom document property, most likely you should be doing it as:
Code:
ActiveDocument.CustomDocumentProperties.Add

Gerry
My paintings and sculpture
 
I just have to add something...hmmm, you are not really looking up Help, are you? Because this thread, and your other thread, could have been answered by yourself in probably one minute. It is right there in Help, and easy to find.

Gerry
My paintings and sculpture
 
Oh yes...I have been at my computer over 12 hours today trying to figure out how to automate word. I have seen more help files, and Tek-tips threads than I can keep track of. The code I am using, I actually got from one of these threads. The problem is the I can't figure out why it will not work with my code. Here is the code...if you have any suggestions how to make it work...or can give me a link to a file that will show me how to easily loop through the properties, it would (hopefully) save me another 12 hours at my computer tomorrow.

Code:
    Dim wd As Object
    Dim doc As Object
    Set wd = CreateObject("word.application")
    Set doc = wd.Document.Open(c:\000054v6.doc")
    
    Dim itmDocProp As ????????
    For Each itmDocProp In doc.CustomDocumentProperties
        If itmDocProp.Name = "Department" Then
            If itmDocProp.Value <> "" Then
                MsgBox itmDocProp.Name & vbCrLf & itmDocProp.Value
            End If
        End If
    Next

I put in the ????? because I wasn't sure what to use here...which brings me back to my original question.

The basic function that I want to do is this....I want to check to see if a custom document property is set up (department). If it is, then change the value. If it is not, then add in the reference.

I know that the code above doesn't do that. It was intended simply to loop through the references and display them for me. It is code that I was trying to run to get an understanding of how the automation process works "real time".

Any suggestions?
 
As you seem to use late binding:
Dim itmDocProp As Object

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thank you. You actually provided me with the key words that I didn't understand, which is "late binding". That took me on a path that I hadn't realized existed, and must be explored!

Thank you very much for the gentle "push" in the right direction!

Lynn
 
That is why I asked:
Could you please state how you are making, and using the instance of Word?
I did not know if you were using early, or late-binding.


Using Object should work.

Since you seem to be aiming for ONE logic result, you may also want to change yor code to:
Code:
If itmDocProp.Name = "Department" AND _
 itmDocProp.Value <> "" Then
    MsgBox itmDocProp.Name & vbCrLf & itmDocProp.Value
End If
as to get that result you do not need a second If..Then logic statement.

Is it actually realistic that you will have a custom document property set as ""? I know it is possible, but if you creating them by code, would you be using a CustomDocumentProperties.Add with a Value:= ""? Perhaps yes, just curious. I certainly can see a scenario whereby one would loop through documents creating empty document properties, if they are going to be set at a later date. Again, just curious.

Gerry
My paintings and sculpture
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top