PC Review


Reply
Thread Tools Rate Thread

Date Formating and building character strings

 
 
C Brandt
Guest
Posts: n/a
 
      17th Aug 2007
I have data files with the names based on dates ordered such that they
naturally appear in order:
Acct 2007-07-23.txt, etc.
In my spreadsheet, i search for complete data and when I find that I am
missing data for a specific date, I would like to enter that date, and have
a procedure work out the filename and load the specfic file.
The yyyy-mm-dd format used to ensure that the files fall in the order of
generation is a little unusual and users don't always catch this and enter
the date incorrectly.
I would simply like to ask for the date needed, and generate the file name
behind the user interface.

I know this doesn't work:
Date needed : 7/23/2007
DN=7/23/2007
Filename = "Acct" & year(DN) & "-" & Month(DN) & "_" & Day(DN) & ".txt"

Any suggestions would be appreciated.
Craig


 
Reply With Quote
 
 
 
 
Ron Rosenfeld
Guest
Posts: n/a
 
      17th Aug 2007
On Fri, 17 Aug 2007 14:39:06 -0500, "C Brandt" <(E-Mail Removed)> wrote:

>I have data files with the names based on dates ordered such that they
>naturally appear in order:
>Acct 2007-07-23.txt, etc.
>In my spreadsheet, i search for complete data and when I find that I am
>missing data for a specific date, I would like to enter that date, and have
>a procedure work out the filename and load the specfic file.
>The yyyy-mm-dd format used to ensure that the files fall in the order of
>generation is a little unusual and users don't always catch this and enter
>the date incorrectly.
>I would simply like to ask for the date needed, and generate the file name
>behind the user interface.
>
>I know this doesn't work:
>Date needed : 7/23/2007
>DN=7/23/2007
>Filename = "Acct" & year(DN) & "-" & Month(DN) & "_" & Day(DN) & ".txt"
>
>Any suggestions would be appreciated.
>Craig
>


="Acct "&TEXT(DN,"yyyy-dd-mm") & ".txt"
--ron
 
Reply With Quote
 
C Brandt
Guest
Posts: n/a
 
      17th Aug 2007
Ron:

Thanks for the speedy reply. Unfortunately it chokes with TEXT highlighted
and gives me a popup with "Compile Error, SUB or Function not defined.
(Code Follows)

Any clues?

Thanks,
Craig


Sub test()
' Cells(3,2) has the date (7/23/07)
DN = Cells(3, 2)
Filename = "Acct " & Text(DN, "yyyy-dd-mm") & ".txt"
End Sub


"Ron Rosenfeld" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Fri, 17 Aug 2007 14:39:06 -0500, "C Brandt" <(E-Mail Removed)>

wrote:
>
> >I have data files with the names based on dates ordered such that they
> >naturally appear in order:
> >Acct 2007-07-23.txt, etc.
> >In my spreadsheet, i search for complete data and when I find that I am
> >missing data for a specific date, I would like to enter that date, and

have
> >a procedure work out the filename and load the specfic file.
> >The yyyy-mm-dd format used to ensure that the files fall in the order of
> >generation is a little unusual and users don't always catch this and

enter
> >the date incorrectly.
> >I would simply like to ask for the date needed, and generate the file

name
> >behind the user interface.
> >
> >I know this doesn't work:
> >Date needed : 7/23/2007
> >DN=7/23/2007
> >Filename = "Acct" & year(DN) & "-" & Month(DN) & "_" & Day(DN) & ".txt"
> >
> >Any suggestions would be appreciated.
> >Craig
> >

>
> ="Acct "&TEXT(DN,"yyyy-dd-mm") & ".txt"
> --ron



 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      17th Aug 2007
Ron gave you a formula that will work in a cell in a worksheet (=text()).

In code, you'd use:
Filename = "Acct " & Format(DN, "yyyy-dd-mm") & ".txt"

C Brandt wrote:
>
> Ron:
>
> Thanks for the speedy reply. Unfortunately it chokes with TEXT highlighted
> and gives me a popup with "Compile Error, SUB or Function not defined.
> (Code Follows)
>
> Any clues?
>
> Thanks,
> Craig
>
> Sub test()
> ' Cells(3,2) has the date (7/23/07)
> DN = Cells(3, 2)
> Filename = "Acct " & Text(DN, "yyyy-dd-mm") & ".txt"
> End Sub
>
> "Ron Rosenfeld" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > On Fri, 17 Aug 2007 14:39:06 -0500, "C Brandt" <(E-Mail Removed)>

> wrote:
> >
> > >I have data files with the names based on dates ordered such that they
> > >naturally appear in order:
> > >Acct 2007-07-23.txt, etc.
> > >In my spreadsheet, i search for complete data and when I find that I am
> > >missing data for a specific date, I would like to enter that date, and

> have
> > >a procedure work out the filename and load the specfic file.
> > >The yyyy-mm-dd format used to ensure that the files fall in the order of
> > >generation is a little unusual and users don't always catch this and

> enter
> > >the date incorrectly.
> > >I would simply like to ask for the date needed, and generate the file

> name
> > >behind the user interface.
> > >
> > >I know this doesn't work:
> > >Date needed : 7/23/2007
> > >DN=7/23/2007
> > >Filename = "Acct" & year(DN) & "-" & Month(DN) & "_" & Day(DN) & ".txt"
> > >
> > >Any suggestions would be appreciated.
> > >Craig
> > >

> >
> > ="Acct "&TEXT(DN,"yyyy-dd-mm") & ".txt"
> > --ron


--

Dave Peterson
 
Reply With Quote
 
Ron Rosenfeld
Guest
Posts: n/a
 
      17th Aug 2007
On Fri, 17 Aug 2007 16:15:33 -0500, "C Brandt" <(E-Mail Removed)> wrote:

>Ron:
>
>Thanks for the speedy reply. Unfortunately it chokes with TEXT highlighted
>and gives me a popup with "Compile Error, SUB or Function not defined.
>(Code Follows)
>
>Any clues?
>
>Thanks,
>Craig


The formula I gave you is for a worksheet cell.

In VBA, in place of the TEXT function, you can use the FORMAT function.


Sub foo()
Const DN As Date = #7/23/2006#
Debug.Print "Acct " & Format(DN, "yyyy-mm-dd") & ".txt"
End Sub

--> Acct 2006-07-23.txt
--ron
 
Reply With Quote
 
C Brandt
Guest
Posts: n/a
 
      18th Aug 2007
Thanks

Craig


"Ron Rosenfeld" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> On Fri, 17 Aug 2007 16:15:33 -0500, "C Brandt" <(E-Mail Removed)>

wrote:
>
> >Ron:
> >
> >Thanks for the speedy reply. Unfortunately it chokes with TEXT

highlighted
> >and gives me a popup with "Compile Error, SUB or Function not defined.
> >(Code Follows)
> >
> >Any clues?
> >
> >Thanks,
> >Craig

>
> The formula I gave you is for a worksheet cell.
>
> In VBA, in place of the TEXT function, you can use the FORMAT function.
>
>
> Sub foo()
> Const DN As Date = #7/23/2006#
> Debug.Print "Acct " & Format(DN, "yyyy-mm-dd") & ".txt"
> End Sub
>
> --> Acct 2006-07-23.txt
> --ron



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Formating strings OldManEd Microsoft Access VBA Modules 1 26th May 2008 09:52 PM
building strings with text and fields =?Utf-8?B?SldDcm9zYnk=?= Microsoft Access Reports 2 19th Apr 2007 03:12 AM
building strings based on common ID =?Utf-8?B?R2l6?= Microsoft Access Queries 1 2nd Mar 2005 11:40 PM
building strings then executing them Brian Henry Microsoft VB .NET 4 23rd Mar 2004 07:34 AM
formating strings into 2 columns active Microsoft VB .NET 3 28th Dec 2003 02:22 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:17 PM.