X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
   Reply to this topicStart new topic
> Trying To Save Using Wdoc.saveas2    
post Nov 16 2017, 04:08 PM

Posts: 528
Joined: 19-November 08
From: Chicago

I am trying to save a Word file under a different name after I open and modify it.

I am using the wDoc.SaveAs2 functionality.

It is not working correctly. It tries to save the file under the original file name. Therefore, I get a prompt something like "The file already exists. Do you want to write over it?" - you know the message.

Why is it not trying to save the file using the path and new file name I give it in the FileName variable?

I can't post the database here, as it has sensitive address information. If you need to see the database, then I will have to do a little work to make a sanitized version. I am happy to do this if necessary.

Thank you.

I am using the following code:

Option Compare Database
Option Explicit

Public Sub ExportNamesToWord()

Dim wApp As Word.Application
Dim wDoc As Word.Document
Dim rs As DAO.Recordset
Dim FileName As String

Set wApp = New Word.Application
Set wDoc = wApp.Documents.Open("C:\Users\David\Documents\Angel Tree\" _
& "Angel Tree Mailing\Angel Tree Volunteer Letters\AngelTreeMailing_Template.docx")
Set rs = CurrentDb.OpenRecordset("CondensedAppReport2017")

If Not rs.EOF Then rs.MoveFirst

wDoc.Bookmarks("Crgvr_FirstName").Range.Text = Nz(rs!CaregiverFirstName, "")
wDoc.Bookmarks("Crgvr_LasttName").Range.Text = Nz(rs!CaregiverLastName, "")
wDoc.Bookmarks("Crgvr_Relationship").Range.Text = Nz(rs!CaregiverRelationship, "")
wDoc.Bookmarks("Crgvr_Address").Range.Text = Nz(rs!CaregiverAddress1, "")
wDoc.Bookmarks("Crgvr_City").Range.Text = Nz(rs!CaregiverCity, "")
wDoc.Bookmarks("Crgvr_ZipCode").Range.Text = Nz(rs!CaregiverZipcode, "")
wDoc.Bookmarks("Crgvr_PrimePhone").Range.Text = Nz(rs!CaregiverPrimaryPhone, "")
wDoc.Bookmarks("Crgvr_ScndPhone").Range.Text = Nz(rs!CaregiverSecondPhone, "")
wDoc.Bookmarks("Crgvr_Email").Range.Text = Nz(rs!CaregiverEmail, "")
wDoc.Bookmarks("Alt_FirstName").Range.Text = Nz(rs!AlternateContactFirstName, "")
wDoc.Bookmarks("Alt_LastName").Range.Text = Nz(rs!AlternateContactLastName, "")
wDoc.Bookmarks("Alt_Relationship").Range.Text = Nz(rs!AlternateContactRelationship, "")
wDoc.Bookmarks("Alt_Phone").Range.Text = Nz(rs!AlternateContactPrimaryPhone, "")
wDoc.Bookmarks("Inmate_Message").Range.Text = Nz(rs!Message, "")

FileName = "C:\Users\David\Documents\Angel Tree\" _
& "Angel Tree Mailing\Angel Tree Volunteer Letters\" & rs!ID & "_AngelTreeLetter.docx"

wDoc.SaveAs2 FileName

wDoc.Close False

Set wDoc = Nothing
Set wApp = Nothing
Set rs = Nothing

End Sub
Go to the top of the page
post Nov 16 2017, 05:23 PM

Posts: 18,324
Joined: 29-March 05
From: Wisconsin


Two things stand out in your code:

1. Your template isn't a .dotx extension, so it's not really a Template file.
2. You're using the word "FileName" as a variable, which is rarely a good idea, since that's a Reserved Word. The interpreter is probably confusing your variable name with the actual Filename.

Try placing a Breakpoint on the line that's doing the SaveAs, and look at the value for FileName to see if it's incorporating the ID value from the recordset or not. If it's not, try using "strFilename" for your variable name instead.

Hope this helps,

Go to the top of the page
post Nov 16 2017, 05:53 PM

Posts: 528
Joined: 19-November 08
From: Chicago


Thank you for your reply.

Regarding your suggestions:

1. Yes, you are right. The word doc. is not a .dotx format. I am simply using bookmarks to insert the text from the database. So, perhaps the document is unfortunately named, but this does not affect the functionality.

2. I did check to see that the FileName variable is correctly creating the right string using the immediate window. It is working correctly. That said, your point is well made. I have changed the name to strFileName.

I am still having the original issue with the wDoc.SaveAs functionality.

I have included a "sanitized" version of the database.

Please offer any additional thoughts.

Attached File(s)
Attached File  AngelTreeMailing_Template.zip ( 46.2K )Number of downloads: 2
Go to the top of the page
post Nov 16 2017, 10:17 PM

Posts: 528
Joined: 19-November 08
From: Chicago

I found the issue.

It was the way my Acer computer was configured with the Acer Cloud add-in.

Here is the reference where I found the issue documented: https://stackoverflow.com/questions/1507807...ill-prompts-why

"Finally found the problem's source.

My Acer computer was installing an Add-in everytime I installed Word. Once I removed the Add-in from Word everything went back to normal.

The Add-in was the AcerCloud Add-in."

I spent almost 2 days trying to figure this out. Ugggh.
Go to the top of the page
post Nov 17 2017, 09:14 AM

Posts: 18,324
Joined: 29-March 05
From: Wisconsin


Wow, that's just ridiculous. I am having a local mom-and-pop computer shop assemble a tower for me from scratch. Really looking forward to getting a new computer that does NOT have all of the "try me, buy me" stuff pre-installed.

Glad you figured it out.

Go to the top of the page

Custom Search

RSSSearch   Top   Lo-Fi    19th November 2018 - 04:30 AM