Solved

Save Rtf file with name as a date using vb6

Posted on 2015-02-22
7
118 Views
Last Modified: 2015-02-22
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
Comment
Question by:isnoend2001
  • 3
  • 3
7 Comments
 
LVL 47

Expert Comment

by:Martin Liss
ID: 40624429
Dim a variable like this

Dim MyDate As Date

then MyDate = txtTaskdate
fName = "C:\Backups\" & MyDate & ".rtf"
0
 
LVL 22

Expert Comment

by:yo_bee
ID: 40624430
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
 
LVL 47

Expert Comment

by:Martin Liss
ID: 40624433
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!

 
LVL 22

Expert Comment

by:yo_bee
ID: 40624443
The issue you will run into is the / / as invalid characters for a file name
0
 
LVL 47

Assisted Solution

by:Martin Liss
Martin Liss earned 250 total points
ID: 40624445
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
 
LVL 22

Accepted Solution

by:
yo_bee earned 250 total points
ID: 40624455
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
 

Author Closing Comment

by:isnoend2001
ID: 40624826
Both ways work thanks
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

726 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