Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Save Rtf file with name as a date using vb6

Posted on 2015-02-22
Medium Priority
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:
how can i do this ?
Question by:isnoend2001
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
LVL 49

Expert Comment

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

Dim MyDate As Date

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

Expert Comment

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

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

Open in new window

LVL 49

Expert Comment

by:Martin Liss
ID: 40624433
Or forget all that and try

fName = "C:\Backups\" & cStr(txtTaskDate) & ".rtf"
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 23

Expert Comment

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

Assisted Solution

by:Martin Liss
Martin Liss earned 1000 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,"/","-")


txtTaskDate = Replace(txtTaskdate,"/","")
LVL 23

Accepted Solution

yo_bee earned 1000 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


Author Closing Comment

ID: 40624826
Both ways work thanks

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

719 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