Solved

Variable File Names

Posted on 2000-03-31
4
131 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 70

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 70

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

860 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