Solved

Variable File Names

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
consolidate or create a new vba code for performing tasks 5 63
JSON Response and request in VB6 application 11 250
VBA filters 2 51
VBA Shell can't Find Word document 11 76
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
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…

920 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

16 Experts available now in Live!

Get 1:1 Help Now