Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using the Actual Time in a "Name" Function

Status
Not open for further replies.

mrfritz44

MIS
Nov 21, 2003
75
US
As the last step in a macro, I want to name my exported text file dynamically with the actual time of the system clock. So far, I've been able to name it according to date, but the time function does not seem to work. Below is an example of the "date name function" that works, and below that is the "time name function" that will not work. What am I doing wrong? Thanks, Fred

Function NamingExercise()
Name "C:\speed\spomcNamingExercise.dta" As "C:\speed\" + Date$ + "spomc.dta"
End Function


Function NamingExercise()
Name "C:\speed\spomcNamingExercise.dta" As "C:\speed\" + Time + "spomc.dta"
End Function
 
I am surprised about the date [ponder]. Certain characters are not allowed in file names, and : is one (Others are \/:*?"<>|). How about:
"C:\speed\" + & Format(Time, "hhnnss") & "spomc.dta
 
I get a compile error. It doesn't like the "&"

The date string is built "12-05-2005spomc.dta
 
Is that because you cut and pasted my mistake :)? I left in a plus sign (+ &) at the beginning.

"C:\speed\" & Format(Time, "hhnnss") & "spomc.dta"
 
Sorry, got it to work.....thanks!

Name "C:\speed\spomcNamingExercise.dta" As "C:\speed\" & Date$ & "_" + Format(Time, "hhnn") & "spomc.dta
 
I'm lost '&' is the normal way to concatenate strings, from Help:
Used to force string concatenation of two expressions.
...
If an expression is not a string, it is converted to a String variant.


What version of Access are you using (for curiosity only; I have Access 2000)? Does it not like ampersands anywhere in code? I have tried with plus (+) and that works for me, as well.
 
Both & and + worked to concatenate the strings. I'm on Access 2003. It even worked mixed. I chnaged them all to &'s to be consistent though.

Fred
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top