K
Kevin J Prince
Greetings.
Not sure what NG this question should be asked in. but perhaps if wrong
someone can point me into the correct area please.. I have a problem
which involves a small piece of VBA code being used in a Word template.
This code uses a data file to hold a number, which is in turn opened,
closed, incremented, opened, updated, then closed. The routine uses a
reference to the computer \\main\C\numbers\number.txt. This file when
opened, opens correctly and the information is duly read and
incremented. But when I go to open and write the data back to the same
\\main\C\numbers\number.txt file I get an error 75. Path /File access
error.
That is if I rem out the on error go to bad output.
Can anyone throw any light on my addressing method please. Code is
below, and is used in a Word document to give a one up number each time
a template is used. The template is held on a single computer and is
used by other computers who have to take the next computer in sequence.
I have tried putting both the number.txt and the .Dot template into a
local folder, changing the sharing on that folder to allow for read and
write. And also I have put both files into the Documents & setting
Shared area.
It will not work on the computer that the files are on, never mind one
of the computers on the network.
AutoNew() is the entry point to the code.
Private Const IniFile = "\\main\C\numbers\number.txt"
Private Property Get NextNumber() As String
Dim temp As String
On Error GoTo BadInput
Open IniFile For Input As #1
Line Input #1, temp
Close #1
NextNumber = temp
Exit Property
BadInput:
NextNumber = "" ' default
End Property
Private Property Let NextNumber(myNumber As String)
On Error GoTo BadOutput
Open IniFile For Output As #1
Print #1, myNumber
Close #1
Exit Property
BadOutput:
MsgBox Prompt:="Unable to store invoice number in" _
& vbCr & IniFile & vbCr & "Check that it's available.", _
Title:="File Error"
End Property
Public Sub AutoNew()
Dim Order As Variant
Order = NextNumber
If Order = "" Then
Order = 1
Else
Order = Order + 1
End If
NextNumber = Order
ActiveDocument.Bookmarks("Order").Range.InsertBefore _
Format(Order, "00#")
ActiveDocument.SaveAs FileName:="path" & Format(Order, "00#") End
Sub
Please any indication as to my addressing method and how it needs to be
correct greatly appreciated.
Regards
Kevin
Not sure what NG this question should be asked in. but perhaps if wrong
someone can point me into the correct area please.. I have a problem
which involves a small piece of VBA code being used in a Word template.
This code uses a data file to hold a number, which is in turn opened,
closed, incremented, opened, updated, then closed. The routine uses a
reference to the computer \\main\C\numbers\number.txt. This file when
opened, opens correctly and the information is duly read and
incremented. But when I go to open and write the data back to the same
\\main\C\numbers\number.txt file I get an error 75. Path /File access
error.
That is if I rem out the on error go to bad output.
Can anyone throw any light on my addressing method please. Code is
below, and is used in a Word document to give a one up number each time
a template is used. The template is held on a single computer and is
used by other computers who have to take the next computer in sequence.
I have tried putting both the number.txt and the .Dot template into a
local folder, changing the sharing on that folder to allow for read and
write. And also I have put both files into the Documents & setting
Shared area.
It will not work on the computer that the files are on, never mind one
of the computers on the network.
AutoNew() is the entry point to the code.
Private Const IniFile = "\\main\C\numbers\number.txt"
Private Property Get NextNumber() As String
Dim temp As String
On Error GoTo BadInput
Open IniFile For Input As #1
Line Input #1, temp
Close #1
NextNumber = temp
Exit Property
BadInput:
NextNumber = "" ' default
End Property
Private Property Let NextNumber(myNumber As String)
On Error GoTo BadOutput
Open IniFile For Output As #1
Print #1, myNumber
Close #1
Exit Property
BadOutput:
MsgBox Prompt:="Unable to store invoice number in" _
& vbCr & IniFile & vbCr & "Check that it's available.", _
Title:="File Error"
End Property
Public Sub AutoNew()
Dim Order As Variant
Order = NextNumber
If Order = "" Then
Order = 1
Else
Order = Order + 1
End If
NextNumber = Order
ActiveDocument.Bookmarks("Order").Range.InsertBefore _
Format(Order, "00#")
ActiveDocument.SaveAs FileName:="path" & Format(Order, "00#") End
Sub
Please any indication as to my addressing method and how it needs to be
correct greatly appreciated.
Regards
Kevin