Home All Groups Group Topic Archive Search About
Author
5 Mar 2009 2:02 AM
Kathy
Hello,
For years I haven't any problems with this code:
Dim FileNum As Long
                        FileNum = FreeFile
                        lname = lpDataFolderName & pUser.Handle & ".txt"
                        Open lname For Append As FileNum
                                Print #FileNum, pUser.FullName & "," &
AdjustedDate
                        ---------------------

Suddenly, I started receiving error message:
"Run time error '52':
Bad file name or number"
and
Print #FileNum, pUser.FullName & "," & AdjustedDate
is highlighted

The code is just copied and pasted.
I do not understand that problem.
Thanks,
Kathy

Author
5 Mar 2009 2:56 AM
Lorin
And what is the filename?
Debug.Print ">" & lname & "<"
and show us

"Kathy" <Kathy@kathy> wrote in message
news:%23Tp%23oZTnJHA.5228@TK2MSFTNGP02.phx.gbl...
> Hello,
> For years I haven't any problems with this code:
> Dim FileNum As Long
>                        FileNum = FreeFile
>                        lname = lpDataFolderName & pUser.Handle & ".txt"

Debug.Print ">" & lname & "<"

Show quoteHide quote
>                        Open lname For Append As FileNum
>                                Print #FileNum, pUser.FullName & "," &
> AdjustedDate
>                        ---------------------
>
> Suddenly, I started receiving error message:
> "Run time error '52':
> Bad file name or number"
> and
> Print #FileNum, pUser.FullName & "," & AdjustedDate
> is highlighted
>
> The code is just copied and pasted.
> I do not understand that problem.
> Thanks,
> Kathy
>
Author
5 Mar 2009 3:06 AM
Bill McCarthy
Hi Kathy,

Are you also closing the file handle ?  Also check to see if
lpDataFolderName includes a path separator, eg "\"



Show quoteHide quote
"Kathy" <Kathy@kathy> wrote in message
news:%23Tp%23oZTnJHA.5228@TK2MSFTNGP02.phx.gbl...
> Hello,
> For years I haven't any problems with this code:
> Dim FileNum As Long
>                        FileNum = FreeFile
>                        lname = lpDataFolderName & pUser.Handle & ".txt"
>                        Open lname For Append As FileNum
>                                Print #FileNum, pUser.FullName & "," &
> AdjustedDate
>                        ---------------------
>
> Suddenly, I started receiving error message:
> "Run time error '52':
> Bad file name or number"
> and
> Print #FileNum, pUser.FullName & "," & AdjustedDate
> is highlighted
>
> The code is just copied and pasted.
> I do not understand that problem.
> Thanks,
> Kathy
>
Author
5 Mar 2009 4:02 AM
Kathy
Please.
If it was the problem with the file name the error would happen a line of
code earlier, wouldn't it?
Kathy

Show quoteHide quote
"Kathy" <Kathy@kathy> wrote in message
news:%23Tp%23oZTnJHA.5228@TK2MSFTNGP02.phx.gbl...
> Hello,
> For years I haven't any problems with this code:
> Dim FileNum As Long
>                        FileNum = FreeFile
>                        lname = lpDataFolderName & pUser.Handle & ".txt"
>                        Open lname For Append As FileNum
>                                Print #FileNum, pUser.FullName & "," &
> AdjustedDate
>                        ---------------------
>
> Suddenly, I started receiving error message:
> "Run time error '52':
> Bad file name or number"
> and
> Print #FileNum, pUser.FullName & "," & AdjustedDate
> is highlighted
>
> The code is just copied and pasted.
> I do not understand that problem.
> Thanks,
> Kathy
>
Author
5 Mar 2009 1:04 PM
argusy
Kathy wrote:
Show quoteHide quote
> Please.
> If it was the problem with the file name the error would happen a line of
> code earlier, wouldn't it?
> Kathy
>
> "Kathy" <Kathy@kathy> wrote in message
> news:%23Tp%23oZTnJHA.5228@TK2MSFTNGP02.phx.gbl...
>> Hello,
>> For years I haven't any problems with this code:
>> Dim FileNum As Long
>>                        FileNum = FreeFile
>>                        lname = lpDataFolderName & pUser.Handle & ".txt"
>>                        Open lname For Append As FileNum
>>                                Print #FileNum, pUser.FullName & "," &
>> AdjustedDate
>>                        ---------------------
>>
>> Suddenly, I started receiving error message:
>> "Run time error '52':
>> Bad file name or number"
>> and
>> Print #FileNum, pUser.FullName & "," & AdjustedDate
>> is highlighted
>>
>> The code is just copied and pasted.
>> I do not understand that problem.
>> Thanks,
>> Kathy
>>
So what has changed, Kathy, if the code has worked for years?

Would pUser.FullName having an apostrophe in it (e.g. "O'Briens") affect it

or has AdjustedDate had its format changed?

That's what you have to look at

Argusy
Author
5 Mar 2009 2:17 PM
Jeff Johnson
"argusy" <arg***@slmember.on.net> wrote in message
news:01bfc302$0$19421$c3e8da3@news.astraweb.com...

>>> Print #FileNum, pUser.FullName & "," & AdjustedDate
>>> is highlighted

> Would pUser.FullName having an apostrophe in it (e.g. "O'Briens") affect
> it

No, she's writing to a file, not SQL Server. An apostrophe isn't going to
affect anything.

> or has AdjustedDate had its format changed?

Again, that's just data going to the file. That won't be the issue.
Author
5 Mar 2009 6:15 PM
Kathy
The problem is related strictly to #FileNum
in Print #FileNum, pUser.FullName & "," & AdjustedDate
BTW, FilNum = 3 which by itself is not correct I think.
Normally I have always FileNum = 1.
When I remove # from #FileNum the error is gone but file of course not
written.
I understand if there were some other events between
FileNum = FreeFile and Print #FileNum, pUser.FullName & "," &
then there is a room for error.
One more note. It is not regular error.
I had IDE running for half a day, that code executed every few minutes, and
after few hours the error hit.
I cannot repeat it so far today.
Thanks,
Kathy


Show quoteHide quote
"Kathy" <Kathy@kathy> wrote in message
news:%23Tp%23oZTnJHA.5228@TK2MSFTNGP02.phx.gbl...
> Hello,
> For years I haven't any problems with this code:
> Dim FileNum As Long
>                        FileNum = FreeFile
>                        lname = lpDataFolderName & pUser.Handle & ".txt"
>                        Open lname For Append As FileNum
>                                Print #FileNum, pUser.FullName & "," &
> AdjustedDate
>                        ---------------------
>
> Suddenly, I started receiving error message:
> "Run time error '52':
> Bad file name or number"
> and
> Print #FileNum, pUser.FullName & "," & AdjustedDate
> is highlighted
>
> The code is just copied and pasted.
> I do not understand that problem.
> Thanks,
> Kathy
>
Author
5 Mar 2009 6:43 PM
dpb
Kathy wrote:
> The problem is related strictly to #FileNum
> in Print #FileNum, pUser.FullName & "," & AdjustedDate
> BTW, FilNum = 3 which by itself is not correct I think.
> Normally I have always FileNum = 1.

That indicates there are open files that haven't been closed previously.
  If you expect this is the only file open by your app then you
definitely have missed a Close somewhere either by a logic branch or an
error branch.

....

Show quoteHide quote
> I understand if there were some other events between
> FileNum = FreeFile and Print #FileNum, pUser.FullName & "," &
> then there is a room for error.
....

>> Dim FileNum As Long
>> FileNum = FreeFile
>> lname = lpDataFolderName & pUser.Handle & ".txt"
>> Open lname For Append As FileNum
>> Print #FileNum, pUser.FullName & "," & AdjustedDate
....
Author
5 Mar 2009 7:11 PM
Kathy
Thank you.
I checked that yesterday and I could not find any missing Close statement
somewhere else.
Interestingly, when the error happened yesterday, I tried to do that:
in the debug state I moved code away from the offending line and I did this:
Close 1
Close 2
and then proceeded to the offending line.
The error was still there.
Thanks,
Kathy

Show quoteHide quote
"dpb" <n***@non.net> wrote in message news:gop6ig$g82$1@aioe.org...
> Kathy wrote:
>> The problem is related strictly to #FileNum
>> in Print #FileNum, pUser.FullName & "," & AdjustedDate
>> BTW, FilNum = 3 which by itself is not correct I think.
>> Normally I have always FileNum = 1.
>
> That indicates there are open files that haven't been closed previously.
> If you expect this is the only file open by your app then you definitely
> have missed a Close somewhere either by a logic branch or an error branch.
>
> ...
>
>> I understand if there were some other events between
>> FileNum = FreeFile and Print #FileNum, pUser.FullName & "," &
>> then there is a room for error.
> ...
>
>>> Dim FileNum As Long
>>> FileNum = FreeFile
>>> lname = lpDataFolderName & pUser.Handle & ".txt"
>>> Open lname For Append As FileNum
>>> Print #FileNum, pUser.FullName & "," & AdjustedDate
> ...
Author
5 Mar 2009 9:38 PM
dpb
Kathy wrote:
....top posting repaired.  Please don't do that...

Show quoteHide quote
> "dpb" <n***@non.net> wrote in message news:gop6ig$g82$1@aioe.org...
>> Kathy wrote:
>>> The problem is related strictly to #FileNum
>>> in Print #FileNum, pUser.FullName & "," & AdjustedDate
>>> BTW, FilNum = 3 which by itself is not correct I think.
>>> Normally I have always FileNum = 1.
>> That indicates there are open files that haven't been closed previously.
>> If you expect this is the only file open by your app then you definitely
>> have missed a Close somewhere either by a logic branch or an error branch.
....
> I checked that yesterday and I could not find any missing Close
> statement somewhere else.
> Interestingly, when the error happened yesterday, I tried to do that:
>  in the debug state I moved code away from the offending line and I
> did this:
> Close 1
> Close 2
> and then proceeded to the offending line.
> The error was still there.
....
Once it occurred I'm not surprised.

Freefile returning "3" indicates that "1" and "2" were in use for some
reason.  Whether by error in logic or an unhandled exception or whatever
the reason.  Otherwise, VB assigns free file ID handles beginning w/ 1.
  An error or other interruption could cause a problem as well.

Using any 3rd part controls or other processes?

--
Author
6 Mar 2009 4:12 PM
Daryl Muellenberg
If you are sure that no other files are supposed to be open, then just do a
Close (without any parameters) before the FreeFile statement and that will
close all open files. The FreeFile statement should then assign 1 for
FileNum every time.

Daryl


Show quoteHide quote
"Kathy" <Kathy@kathy> wrote in message
news:e7Q3tYcnJHA.996@TK2MSFTNGP03.phx.gbl...
> Thank you.
> I checked that yesterday and I could not find any missing Close statement
> somewhere else.
> Interestingly, when the error happened yesterday, I tried to do that:
> in the debug state I moved code away from the offending line and I did
> this:
> Close 1
> Close 2
> and then proceeded to the offending line.
> The error was still there.
> Thanks,
> Kathy
>
> "dpb" <n***@non.net> wrote in message news:gop6ig$g82$1@aioe.org...
>> Kathy wrote:
>>> The problem is related strictly to #FileNum
>>> in Print #FileNum, pUser.FullName & "," & AdjustedDate
>>> BTW, FilNum = 3 which by itself is not correct I think.
>>> Normally I have always FileNum = 1.
>>
>> That indicates there are open files that haven't been closed previously.
>> If you expect this is the only file open by your app then you definitely
>> have missed a Close somewhere either by a logic branch or an error
>> branch.
>>
>> ...
>>
>>> I understand if there were some other events between
>>> FileNum = FreeFile and Print #FileNum, pUser.FullName & "," &
>>> then there is a room for error.
>> ...
>>
>>>> Dim FileNum As Long
>>>> FileNum = FreeFile
>>>> lname = lpDataFolderName & pUser.Handle & ".txt"
>>>> Open lname For Append As FileNum
>>>> Print #FileNum, pUser.FullName & "," & AdjustedDate
>> ...
>
>
Author
6 Mar 2009 7:57 PM
dpb
Daryl Muellenberg wrote:
> If you are sure that no other files are supposed to be open, then just do a
> Close (without any parameters) before the FreeFile statement and that will
> close all open files. The FreeFile statement should then assign 1 for
> FileNum every time.
....
But the point is that if it isn't unity and there's no intent for other
files to be open, that's indicative that there's a bug somewhere that
needs to be tracked down and is probably at least related to the
symptoms if not the absolute cause.

--
Author
7 Mar 2009 1:56 AM
Jeremiah D. Seitz
On Thu, 5 Mar 2009 14:11:22 -0500, "Kathy" <Kathy@kathy> wrote:

>Thank you.
>I checked that yesterday and I could not find any missing Close statement
>somewhere else.
>Interestingly, when the error happened yesterday, I tried to do that:
>in the debug state I moved code away from the offending line and I did this:
>Close 1
>Close 2
>and then proceeded to the offending line.
>The error was still there.

Did you Shift-F9 to the line that caused the error? If not, the Err
object would retain the *previous* error, as opposed to a "no error"
condition if the closing worked.

FYI, the Reset command should close all open files, but I would only
recommend that as a band-aid(tm).

>Thanks,
>Kathy

    HTH,

    J.
    Jeremiah D. Seitz
    Omega Techware
    http://www.omegatechware.net
Author
7 Mar 2009 7:52 PM
Nobody
Show quote Hide quote
"Kathy" <Kathy@kathy> wrote in message
news:%23Tp%23oZTnJHA.5228@TK2MSFTNGP02.phx.gbl...
> Hello,
> For years I haven't any problems with this code:
> Dim FileNum As Long
>                        FileNum = FreeFile
>                        lname = lpDataFolderName & pUser.Handle & ".txt"
>                        Open lname For Append As FileNum
>                                Print #FileNum, pUser.FullName & "," &
> AdjustedDate
>                        ---------------------
>
> Suddenly, I started receiving error message:
> "Run time error '52':
> Bad file name or number"
> and
> Print #FileNum, pUser.FullName & "," & AdjustedDate
> is highlighted

When Print# or Put through that error, it means that file size has just
exceeded 2 GB.