Posted on 2010-09-17
Last Modified: 2012-05-10

Run-time error '52'

Bad file name or number

On debug highlighted on following line
Open csvflname for output as #iFileNo

Dim iFileNo as integer
dim csvflname as integer

csvflname = text1(8) & ".csv"

Open csvflname for output as #iFileNo

Open in new window

Question by:crystalsoft
LVL 13

Expert Comment

ID: 33700510

Where is the varible 'text1' initialized?  Try printing csvfilename and text1 for debug purposes.

LVL 53

Expert Comment

ID: 33700554
Make sure that csvflname = text1(8) & ".csv" contains a valid name and not something like this ".csv"
Check the value of text1(8)

Author Comment

ID: 33700566

Thanks for quick reply sir

text1(8) is a text box

csvflname = text1(8) & ".csv"

on debug i am getting file name like 43.csv

43 is value from text1(8)
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

LVL 40

Assisted Solution

by:Kyle Abrahams
Kyle Abrahams earned 125 total points
ID: 33700598
does 43.csv exist?

try text1(8).text

see this link:
LVL 53

Accepted Solution

Dhaest earned 125 total points
ID: 33700601
What is the value of #iFileNo ?

Perhaps you need to add something like this:

#iFileNo = freefile()
Open csvflname for output as #iFileNo
LVL 14

Expert Comment

ID: 33702367
Just an observation no one picked up on, and something to watch out for in the future. In your original posted code, you declared csvflname as an integer, then assigned a text value to it. That's a no-no.
Fixing that and setting iFileNo with FreeFile would have made the code work (assuming text1(8) is a valid control on your form).

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This is about my first experience with programming Arduino.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question