Re: VB local drive addressing
From: Karl E. Peterson (karl_at_mvps.org)
Date: 01/24/05
- Next message: Karl E. Peterson: "Re: Copying text from Code module and pasting into MS Word"
- Previous message: Steve Rindsberg: "Re: Saving a Powerpoint file as a JPeg"
- In reply to: Kevin J Prince: "VB local drive addressing"
- Next in thread: Kevin J Prince: "Re: VB local drive addressing"
- Reply: Kevin J Prince: "Re: VB local drive addressing"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 24 Jan 2005 11:22:19 -0800
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
--
[Microsoft Basic: 1976-2001, RIP]
Kevin J Prince wrote:
> 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
- Next message: Karl E. Peterson: "Re: Copying text from Code module and pasting into MS Word"
- Previous message: Steve Rindsberg: "Re: Saving a Powerpoint file as a JPeg"
- In reply to: Kevin J Prince: "VB local drive addressing"
- Next in thread: Kevin J Prince: "Re: VB local drive addressing"
- Reply: Kevin J Prince: "Re: VB local drive addressing"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|