Word won't save where i want it to...

J

James

Hi Everyone,

i hope i'm not using improper etiquette here, i posted this on
Microsoft.public.word.newusers first and as recommended to come here:


I have code in a Word template that, upon SAVE, should save to the
same folder that the .Dat file exists. However, for myself and one
other user it saves a completely different drive on the network. I
have about 30 people using the template, and everyone else seems to
be ok. My guess is that i tried to save this template to my C Drive
and somehow created a .dat file somewhere else that i can't find. Any ideas?
It's Word
2003 on Windows 2000.

here is the code:

Option Explicit

Public Function GetOrderNum() As String
Dim sPath As String
'Point to the data file with the same name
sPath = Left(Me.FullName, Len(Me.FullName) - 3) & "dat"


'Read the ordernum from the file
GetOrderNum = System.PrivateProfileString(sPath, "Settings", "OrderNum")

'if the ordernum key is missing or it is a new file then start at 1
If GetOrderNum = "" Then
GetOrderNum = "1"
End If

'Write the updated value back to the file
System.PrivateProfileString(sPath, "Settings", "OrderNum") =
CStr(CInt(GetOrderNum) + 1)

'Format the Order number with leading zeros
GetOrderNum = Format(GetOrderNum, "00000")
GetOrderNum = "DEL" & GetOrderNum

End Function

TIA

James
 
J

Jay Freedman

Hi James,

Good to see you here. :)

I think you're confusing two things here. The code you show doesn't actually
save the document, it just figures out what order number to put in the
string. The .dat file contains only that number, and each time you use this
function the number gets updated. The code will look for the .dat file in
the same folder as the template (the name Me refers to the template, so
Me.Fullname gives you the path to the template file). So if you're talking
about the document being saved to the wrong disk, that must be happening in
a different part of your code. Look for a subroutine named FileSaveAs, and
see how it saves the document.

If it's the .dat file that's going to the wrong place, try this: Open the
VBA editor and open this function in it. Click in the gray margin to the
left of the line sPath = Left.... to put a breakpoint there (or just click
on the line and use the menu command Debug > Toggle Breakpoint, or its
shortcut F9). Now run the macro as you normally would. The code will stop at
the breakpoint, just before executing that line. Press F8 to execute that
one statement. Now hover the mouse over sPath, and the tooltip will show you
its value. Is it what you expect?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top