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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SaveAs causes a file to be locked until window is closed

Status
Not open for further replies.

nemosys

Programmer
Oct 10, 2001
5
US
I am opening a HTML file in Word and using the SaveAS command to save it to a different name. Next I try to load the file to a ADODB.Stream and get an error stating that the file is locked. Here is part of the code:

Word.ActiveDocument.SaveAs wfileName
Set cn = CreateObject("ADODB.Connection")
cn.ConnectionString = "Provider=sqloledb;Data Source="
cn.ConnectionString = cn.ConnectionString & "PHILL\SQL2000" & ";Initial Catalog=" & "umantest" & ";User id=sa;password=;"
cn.CursorLocation = adUseClient
cn.Open
Set Cmd = CreateObject("ADODB.Command")
Set Cmd.ActiveConnection = cn
Set stm = New ADODB.Stream
rs.Open "select * from policy where PKPOL1 = " & policy, cn, adOpenKeyset, adLockOptimistic
stm.Type = adTypeBinary
stm.Open
stm.LoadFromFile (wfileName)
rs!DOM = stm.Read
rs.Update
rs.Close
stm.Close
Set Cmd = Nothing
Set rs = Nothing
Set stm = Nothing
Word.ActiveWindow.Close
Unload Me

The stm.LoadFromFile fails with a file locked error message.
If there some way to unlock the file so stm can read the file?
 
nemosys,

I don't quite understand exactly what you are doing, but you r doing a save as so therefore the doc will still be open. Don't u need to close the activeDocument first?

Nick
 
Hi,

This code is in a macro contained in a word template. When a user uses this template the macro is run when the document is opened.

If I use Word.ActiveDocument.Close the macro does not finish executing. Is there another way to close the file instead of using the SaveAs command?

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top