• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 125
  • 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 LissOlder than dirtCommented:
Dim a variable like this

Dim MyDate As Date

then MyDate = txtTaskdate
fName = "C:\Backups\" & MyDate & ".rtf"
0
 
yo_beeDirector of Information TechnologyCommented:
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 LissOlder than dirtCommented:
Or forget all that and try

fName = "C:\Backups\" & cStr(txtTaskDate) & ".rtf"
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
yo_beeDirector of Information TechnologyCommented:
The issue you will run into is the / / as invalid characters for a file name
0
 
Martin LissOlder than dirtCommented:
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 Information TechnologyCommented:
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

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

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