Results 1 to 11 of 11
  1. #1
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480

    Naming scheme thru VBA


    I am setting up reports to run each night, around 25 of them. This will create a file called trace.log. I am able to rename the file without issue. However I need the file name to be a date and time stamp.

    Code:
    Name "C:\Program Files\Ericom Software\PowerTerm\trace.log" As "C:\Test1.xls"
    I have seen this done in excel, but I am wondering if I can accomplish this thru the VBA code itself. Eventually, I will have the report named as "Location&Date&time.xls" Any ideas or fingers pointed in the right direction is greatly appreciated.
    Last edited by redbull; 04-10-2012 at 12:32 PM.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Name "C:\Program Files\Ericom Software\PowerTerm\trace.log" As "C:\Test1" & Format(Now(), "FormatOfYourChoice") & ".xls"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    R_Badger is offline Knows a few tricks
    Windows XP Access 2003
    Join Date
    Feb 2012
    Location
    Suffolk, UK
    Posts
    262
    You probably want something along the lines of:

    Code:
    Dim thisday as string
    dim taskpath as string
    thisday= now()
    taskpath="C:\your_filepath_here\filename"& thisday &".snp"
    docmd.outputto acoutputreport, "report_name", acformatsnp, taskpath, false
    Edit: should have re-read it first, Pbaldys is simpler and actually what you are after!
    Last edited by R_Badger; 04-10-2012 at 08:57 AM. Reason: I should have re-read before i posted lol!

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    In my experience you need to use the Format function, as otherwise you'll get "4/10/2012" and the slashes will cause an error in the file name. Also, I use "yyyymmdd" as that makes it sort properly.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    R_Badger is offline Knows a few tricks
    Windows XP Access 2003
    Join Date
    Feb 2012
    Location
    Suffolk, UK
    Posts
    262
    You are entirely correct, now you mention it I remember discovering that the hard and annoying way.

  6. #6
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480
    Well thank you everyone. Going to mark this as solved.

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Glad you got it sorted out.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480
    Well all the help here is what fixed it. Quick question, is there a way to add a timestamp to the file name? yyyymmdd then time?

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    ?format(now(),"yyyymmddhhmm")
    201204101322
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480
    its military time and that works for me! thanks again!!

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    No problemo!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Macro - Filter by scheme
    By erikl1 in forum Access
    Replies: 3
    Last Post: 02-27-2012, 01:26 PM
  2. Newbie question re naming columns
    By Kola in forum Access
    Replies: 4
    Last Post: 10-03-2011, 06:44 AM
  3. Naming conventions
    By Yesideez in forum Database Design
    Replies: 3
    Last Post: 06-29-2011, 08:55 AM
  4. Naming a Calculated Field
    By wscott in forum Reports
    Replies: 4
    Last Post: 10-11-2010, 02:20 AM
  5. Table naming - use prefix or not?
    By revnice in forum Access
    Replies: 4
    Last Post: 08-08-2010, 11:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums