Solved

Save Rtf file with name as a date using vb6

Posted on 2015-02-22
7
115 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 45

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 21

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 45

Expert Comment

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

fName = "C:\Backups\" & cStr(txtTaskDate) & ".rtf"
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 21

Expert Comment

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

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 21

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

746 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now