Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 124
  • Last Modified:

Save Rtf file with name as a date using vb6

I am trying to make a personal reminder program.
I have a calendar control that puts a date into a textbox to be the rtfs file name.
the date format looks like this: 2/21/2015
I get this error:
The specified filename cannot be accessed or is invalid


fName = "C:\Backups\" & txtTaskDate & ".rtf"
debug results fName:
        C:\Backups\2/21/2015.rtf
how can i do this ?
0
isnoend2001
Asked:
isnoend2001
  • 3
  • 3
2 Solutions
 
Martin LissRetired ProgrammerCommented:
Dim a variable like this

Dim MyDate As Date

then MyDate = txtTaskdate
fName = "C:\Backups\" & MyDate & ".rtf"
0
 
yo_beeDirector of ITCommented:
The Wacks will cause this to error out.
you should parse the date mm-dd-yyyy or something else other than mm/dd/yyyy
Try using :
(Format(Now(), "yyyymmddhhMM")

Open in new window

or
(Format(Now(), "mm-dd-yyyy"))

Open in new window

0
 
Martin LissRetired ProgrammerCommented:
Or forget all that and try

fName = "C:\Backups\" & cStr(txtTaskDate) & ".rtf"
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
yo_beeDirector of ITCommented:
The issue you will run into is the / / as invalid characters for a file name
0
 
Martin LissRetired ProgrammerCommented:
Yes that's right, I forgot about that.

To change it so that it's acceptable you could do something like

txtTaskDate = Replace(txtTaskdate,"/","-")

or

txtTaskDate = Replace(txtTaskdate,"/","")
0
 
yo_beeDirector of ITCommented:
Hence my command of format.  Not saying that you can not do it with a replace, but you are adding additional steps rather than a format function.
Sub Test()
Dim mydate As String

mydate = "02/21/2015"


Debug.Print (Format(txtTaskDate, "mm-dd-yyyy"))


End Sub

Open in new window

0
 
isnoend2001Author Commented:
Both ways work thanks
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now