Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Problem when using Access code to populate a Word doc

Posted on 2008-06-11
3
Medium Priority
?
230 Views
Last Modified: 2013-11-27
I'm using Access code to populate a Word report.
I have a recordset to get the values from db tables, and replace or insert at bookmarks of Word. Then save the doc and close the recordset.
Everytime there is a msg of MS Word came out: This file is in use by another application or user. (C:\Documents and Settings\...\Normal.dot).
If I click on "OK" and try to close it, another msg: Changes have been made that affect the global template, Normal. Do you want to save those changes?
What do they mean? Why I got these msg?
'These are the codes I'm using
    Option Explicit
    Public appWord As Word.Application
    Public doc2 As Word.Document
 
    Dim cn As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    Set appWord = New Word.Application
    cn.Open CurrentProject.Connection.ConnectionString
    rs.Open...
 
    doc2.SaveAs...
    appWord.Visible = True
    appWord.Quit
    rs.Close
    cn.Close

Open in new window

0
Comment
Question by:angie_angie
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 27

Expert Comment

by:MikeToole
ID: 21760847
I presume that you want to open a new document based on a template or another existing document? I don't see that step in your code.
It should be set up something like the sample shown in the snippet.
    Dim appWord As New Word.Application
    Dim doc As Word.Document
    Dim bkm As Word.Bookmark
    Set doc = appWord.Documents.Add(cPath & "BookmarkTest.dot")
    ...   ' do your work with the bookmarks here
    On Error Resume Next
    Kill cPath & "BookmarkTest.doc"
    On Error GoTo 0
    doc.SaveAs cPath & "BookmarkTest.doc", , , , False
    doc.Close
    appWord.Quit

Open in new window

0
 

Author Comment

by:angie_angie
ID: 21765953
MikeToole,
Yes you're right, and I do have the similar code except I don't have "doc.Close" since the user wants to view the report immediately after generated.
But I always have the problem I mentioned. I don't know why there is a global template called "Normal".
Even I delete it, it will come out again next time.
0
 
LVL 27

Accepted Solution

by:
MikeToole earned 1500 total points
ID: 21766643
There is always a global template called Normal, it's where Word gets the defaults for a new document when you don't specify another template. If you delete it, Word will recreate it with installation defaults next time it runs.
If you're making Word visible so that the user can see it, you shouldn't use appWord.Quit - that will close the instance of Word that has the document open and the user will have nothing to see!
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question