PC Review


Reply
Thread Tools Rate Thread

Document is locked for editing by user.

 
 
PBI
Guest
Posts: n/a
 
      14th Oct 2008
I am attempting to insert data in a Word document from an Access
database using VB6 code. The code compiles without errors; however, when
executed the locked for editing error pops up. I know that the document is
not in use and the error message is triggered by:

Set MSWordDoc = wd.Documents.Open("H:\Test2.doc", , False, , , , , , , , ,
False)

Sub code follows:

Public Sub EdDoc(strField1 As String)
Const Find = "[OCCASION]"
Dim MSWordDoc As Document
Dim wd As New Word.Application
Dim rng As Range
Dim hf As HeaderFooter
Dim s As Section
Set MSWordDoc = wd.Documents.Open("H:\Test2.doc", , False, , , , , , , , ,
False)
Set rng = hf.Range
With rng.Find
.Text = Find
.Replacement.Text = strField1
.Execute Replace:=wdReplaceAll
End With
DoCmd.Save ("H:\Notice.doc")
DoCmd.Close
wd.Quit
End Sub

Please help.
--
Paul
 
Reply With Quote
 
 
 
 
Tom van Stiphout
Guest
Posts: n/a
 
      15th Oct 2008
On Tue, 14 Oct 2008 10:38:08 -0700, PBI
<(E-Mail Removed)> wrote:

Change that to:
Dim MSWordDoc As Word.Document
or you may get a Type Mismatch.

Also, be sure to run Task Manager (alt_ctrl_del > Task Manager >
Processes and be sure that MsWord is not running. It could be running
invisibly (especially if you set that argument to False).

-Tom.
Microsoft Access MVP


> I am attempting to insert data in a Word document from an Access
>database using VB6 code. The code compiles without errors; however, when
>executed the locked for editing error pops up. I know that the document is
>not in use and the error message is triggered by:
>
>Set MSWordDoc = wd.Documents.Open("H:\Test2.doc", , False, , , , , , , , ,
>False)
>
>Sub code follows:
>
>Public Sub EdDoc(strField1 As String)
>Const Find = "[OCCASION]"
>Dim MSWordDoc As Document
>Dim wd As New Word.Application
>Dim rng As Range
>Dim hf As HeaderFooter
>Dim s As Section
>Set MSWordDoc = wd.Documents.Open("H:\Test2.doc", , False, , , , , , , , ,
>False)
>Set rng = hf.Range
> With rng.Find
> .Text = Find
> .Replacement.Text = strField1
> .Execute Replace:=wdReplaceAll
> End With
>DoCmd.Save ("H:\Notice.doc")
>DoCmd.Close
>wd.Quit
>End Sub
>
>Please help.

 
Reply With Quote
 
PBI
Guest
Posts: n/a
 
      15th Oct 2008
Thanks Tom. Your change in addition to changing the ReadOnly parameter
to True got me past that error. However, the program exits the subroutine at
the next set statement. Am I approaching the correctly? Iam a programmer ;
but, I don't speak VB. The text I am trying to replace is in the body of the
document, not the header. I would like the Replace command to search the
entire document for the string provided.
--
Paul


"Tom van Stiphout" wrote:

> On Tue, 14 Oct 2008 10:38:08 -0700, PBI
> <(E-Mail Removed)> wrote:
>
> Change that to:
> Dim MSWordDoc As Word.Document
> or you may get a Type Mismatch.
>
> Also, be sure to run Task Manager (alt_ctrl_del > Task Manager >
> Processes and be sure that MsWord is not running. It could be running
> invisibly (especially if you set that argument to False).
>
> -Tom.
> Microsoft Access MVP
>
>
> > I am attempting to insert data in a Word document from an Access
> >database using VB6 code. The code compiles without errors; however, when
> >executed the locked for editing error pops up. I know that the document is
> >not in use and the error message is triggered by:
> >
> >Set MSWordDoc = wd.Documents.Open("H:\Test2.doc", , False, , , , , , , , ,
> >False)
> >
> >Sub code follows:
> >
> >Public Sub EdDoc(strField1 As String)
> >Const Find = "[OCCASION]"
> >Dim MSWordDoc As Document
> >Dim wd As New Word.Application
> >Dim rng As Range
> >Dim hf As HeaderFooter
> >Dim s As Section
> >Set MSWordDoc = wd.Documents.Open("H:\Test2.doc", , False, , , , , , , , ,
> >False)
> >Set rng = hf.Range
> > With rng.Find
> > .Text = Find
> > .Replacement.Text = strField1
> > .Execute Replace:=wdReplaceAll
> > End With
> >DoCmd.Save ("H:\Notice.doc")
> >DoCmd.Close
> >wd.Quit
> >End Sub
> >
> >Please help.

>

 
Reply With Quote
 
Tom van Stiphout
Guest
Posts: n/a
 
      15th Oct 2008
On Wed, 15 Oct 2008 03:13:01 -0700, PBI
<(E-Mail Removed)> wrote:

I don't often program in Word. Typically I first create a macro in
Word that I record the action in that I want to program. Then I look
at the VBA that was generated, and it gives me the basis for my code.

In your case I think you're missing "Selection.WholeStory" to select
all text.

-Tom.


> Thanks Tom. Your change in addition to changing the ReadOnly parameter
>to True got me past that error. However, the program exits the subroutine at
>the next set statement. Am I approaching the correctly? Iam a programmer ;
>but, I don't speak VB. The text I am trying to replace is in the body of the
>document, not the header. I would like the Replace command to search the
>entire document for the string provided.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Locked from editing a document PopNJ Microsoft Word Document Management 1 8th Mar 2009 01:29 PM
The document is locked for editing by another user davehunter64 Microsoft Excel Misc 1 24th Jun 2008 01:18 PM
excel document locked for editing =?Utf-8?B?a3Jpc2g=?= Microsoft Excel Setup 3 16th Nov 2005 08:17 PM
Re: Document locked for editing by 'setimage', JulieD Microsoft Excel Misc 0 25th Aug 2004 04:39 PM
How to intercept if the document is locked for editing ? =?Utf-8?B?QWNoaWxsZSBmcm9tIEl0YWx5?= Microsoft Word Document Management 1 27th Mar 2004 01:07 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:59 PM.