Word Export and Import Problem

smbarney

Registered User.
Local time
Today, 08:18
Joined
Jun 7, 2006
Messages
60
Using bookmarks, I am exporting some data from by database to a Word document, which is then attached to an email.

The receipt of the email is suppose to respond the information contained in the document using text fields and five comboboxes and email back so we can automatically import the response back into our database. The problem is that in order to get the comboboxes to work you have to protect the word document first. Once protected, Word will not permit me to automatically fill in the data fields.

Is there a way to have Access enable document protection after it has exported the data to the word file?
 
This is the code I am using. It keeps telling me that an Object is required. Any thoughts?




Code:
Set MyWord = CreateObject("Word.Application")
MyWord.Visible = True
Set HHForm = objWord.Documents.Add("\\c2\hub\Documents\TempFiles\SubjectTW.doc")
MyWord.Activate


MyWord.ActiveDocument.UnProtect Password:="jennifer"
   

  
MyWord.ActiveDocument.Bookmarks("RFINumber").Select
MyWord.Selection.Text = Me.RFINumber.Value
        

MyWord.ActiveDocument.SaveAs fileName:="\\c2\hub\Documents\TempFiles\" & Me.RFINumber, FileFormat:=wdFormatDocument
MyWord.ActiveDocument.Protect Type:=2, NoReset:=1, Password:="jennifer"
MyWord.ActiveDocument.Close Savechanges:=wdSaveChanges

Set MyWord = Nothing
Set HHForm = Nothing
 
Which line is giving the error?

Do you have

Dim MyWord as Object

in your code.
 
Yes, I do have Dim Myword as object--sorry forgot to include it.

I don't know which line its. I just get an error message indicating that it needs an object and that is it.
 
Well then put a breakpoint in your code and step through the code line by line using F8 till hit the error.
 
Good points Rabbie as usual. On a related note, he seems to have two Word objects called MyWord and objWord - shouldn't these be one and the same?

Set MyWord = CreateObject("Word.Application")
Set HHForm = objWord.Documents

Maybe I'm missing something here.
 
Good points Rabbie as usual. On a related note, he seems to have two Word objects called MyWord and objWord - shouldn't these be one and the same?

Set MyWord = CreateObject("Word.Application")
Set HHForm = objWord.Documents

Maybe I'm missing something here.
I think that is the reason for his error message. I missed when I looked at the code so well spotted.:)
 
You are correct, jal. I removed the second reference and cleaned up the code a somewhat and it works wonderfully. Thanks
 

Users who are viewing this thread

Back
Top Bottom