using a textbox value as a string in a file name

deejay_totoro

Registered User.
Local time
Today, 15:20
Joined
May 29, 2003
Messages
169
Hello,

I am trying to take the value of a text box and include it in the file name of a file that is exported from a database.

The code looks like this:

dim strFileName = some text box date value
strMyVariable = "c:\directory" & Format(Date, "DD / MY", strFileName) & ".csv"


Basically I would like to include the value of the text box in the file name - but so far cant get it to work.

This code is producing an error on the date format....

Any a help would be appreciated.

Thanks,

dj_T
 
deejay_totoro said:
Hello,

I am trying to take the value of a text box and include it in the file name of a file that is exported from a database.

The code looks like this:

dim strFileName = some text box date value
strMyVariable = "c:\directory" & Format(Date, "DD / MY", strFileName) & ".csv"


Basically I would like to include the value of the text box in the file name - but so far cant get it to work.

This code is producing an error on the date format....

Any a help would be appreciated.

Thanks,

dj_T

1. You have it switched, it should look like this:

strmyvariable = "c:\directory" & Format(strFileName, "DD / MY") & ".csv"

However, you are going to run into problems. First, the slash will be treated as a directory because you can't have slashes in filenames, so it will actually create a file in your DD directory names your MY.csv. Second, your Year will not show right, since you only have one digit, I would go with something like this:

strmyvariable = "c:\directory\" & Format(strFileName, "DD-MM-YYYY") & ".csv"

or something alone those lines.

HTH
 
Something like this should be OK:

dim strFileName as string
dim strMyVariable as string

strFileName = Format (myTextBox.Value, "dd-mm-yy")
strMyVariable = "c:\directory\" & strFileName & ".csv"

Note that there needs to be a trailing "\" after the directory and that "/" is an illegal character in a file name.
 
strmyvariable = "c:\directory\" & Format(strFileName, "YYYY-MM-DD") & ".csv"

The YYYYMMDD format will be easier to read since the files will be easier to find when sorted by file name.
 

Users who are viewing this thread

Back
Top Bottom