VB local drive addressing

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
 
K

Karl E. Peterson

Hi Kevin --

Not sure what the issue is there, because I was absolutely unable to recreate it
here. I used this code, which differs from your own only in the name of the output
file and how the autonumbering is presented to the user:

Option Explicit

Private Const IniFile = "\\ntcl01\public\test.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
MsgBox "This is order #" & Order
End Sub

The template was stored locally, and the text file is off on an unrestricted (dumping
ground) network share. This leaves just two possibilities. Either another instance
of your template is reading the file at the exact moment you're trying to write it,
or you don't have write permissions where the file is? Do you perhaps have Create,
but not Modify, permissions in this folder?

If you're looking for tips, I would suggest you not use explicit file handles. Do
something like this, instead:

Dim hFile As Long
hFile = Freefile()
Open "whatever.txt" For Input Access Read As #hFile
Line Input #hFile, temp
' and so on...

Sorry... Karl
 
K

Kevin J Prince

Karl,

Thanks for the reply.

Something's not right here then..... Hmmmm

Can you humour me please...

explore | C:\ root folder
File | Empty space on the right of the screen | right mouse | New folder
create folder and give it a name....
go to sharing and create a share name, and allow other to change
create the file number.txt
enter some number or other.

I even have the whole C: drive shared at the moment. No other PC's on
the network.


That, To my old and tired mind, should be that.

Or have I made a fundamental mistake somewhere and missed a bit
out...????

Regards Kevin
 
S

Steve Rindsberg

Karl,

Thanks for the reply.

Something's not right here then..... Hmmmm

Can you humour me please...

explore | C:\ root folder
File | Empty space on the right of the screen | right mouse | New folder
create folder and give it a name....
go to sharing and create a share name, and allow other to change

Shouldn't you then access the file as:

\\servername\sharename\file
or
\\servername\sharename\subfolder\file

You don't need the "c" in "\\servername\c\sharename\filename"
 
K

Karl E. Peterson

I could give that a shot, Kevin, but the results would be the same. On my machine,
when I create a new share, by default "Everyone" has "Full Control." Have you looked
at the permissions for *both* the share *and* the folder/file itself?

Later... Karl
 
K

Kevin J Prince

Thanks for the replies,

last two gave me a clue where I was going wrong......

OK to check and be certain what address I should use I went into
explorer then network neighbourhood then filtered my way to what I
thought was the address (taken from the 'My Network Places' followed by
the 'Microsoft Windows Network' then the workgroup name
Selecting the PC on the network. Pressing the plus sign, seeing the
shared drive designator pressing the plus sign, and working my way to
the shared drive folder. Now did you notice that... I did'nt
\\Main\C\PublicData
C was the default name I had left in for the shared drive, and there
below it was the correct folder. So I ended up with the above
pathname... No need to go further, it's their in black and white.......!

If, however, I had looked further down, I would have noticed that the
same folder was referenced again as
\\Main\PublicData
also existed (as above) and in fact is the correct one.

It is now working!

Thanks to all that have actually read my plea's, I think my hair may
start growing back soon, most of it pulled out by the roots because I
did not see the difference between the same folder......
AArrrgggghhhhhh!

What an idiot, OK not need for follow ups on the last statement....
 

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

Similar Threads


Top