Solved

Variable File Names

Posted on 2000-03-31
4
128 Views
Last Modified: 2010-05-02
We are trying to use VB to develop a small program to populate a series of small data files used by another legacy application.  Does anyone know how to create the data file (file name) to include the date?  For example, a file name for a file created on 3/31 would be AAA0331.txt; a file created on 4/1 would be AAA0401.txt etc.
0
Comment
Question by:Winchesters
  • 2
4 Comments
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 2673011
You can use the Format function:
sFile = "AAA" & format(date,"mmdd") & ".txt"
0
 
LVL 4

Expert Comment

by:gcs001
ID: 2673026
Or this way:
Dim fn As String

fn = "AAA" & Format(Month(Now), "00") & Format(Day(Now), "00") & ".txt"
Open fn For Output As #1 '
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2673305
I like to add the Last digit of the year in my file names.. ie. Format = AAAymmdd

<----- Code Begin ----->

Dim dteWork As Date
dteWork = #12/31/1998#

Dim intYear As Integer
intYear = Year(dteWork)
intYear = intYear - ((intYear \ 10) * 10)

Dim strFileName as String
strFileName = "AAA" _
   & Format(intYear, "0") _
   & Format(Month(dteWork), "00") _
   & Format(Day(dteWork), "00") _
   & ".txt"

Dim intFileNumber
intFileNumber = Freefile
Open strFileName For Write as intFileNumber

<----- Code End ----->
0
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 50 total points
ID: 2673381
You could also use:

strFileName = "AAA" _
   & Right(Year(dteWork), 1) _
   & Format(Month(dteWork), "00") _
   & Format(Day(dteWork), "00") _
   & ".txt"
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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…

744 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

11 Experts available now in Live!

Get 1:1 Help Now