Solved

Adding time to a copied table

Posted on 2013-01-11
10
150 Views
Last Modified: 2013-03-29
I want to add the current time to the end of the table that I am selecting into.  Right now I am only adding the date which comes out as: MyTable_20130111.  I would like it to have the date on the end as:
MyTable_20130111_10:38:00 PM.
Here is my code that I have now:
Function BkupLastEntry()
With DoCmd
    .SetWarnings False
    .RunSQL "SELECT * INTO MyTable_" & Format(Now, "yyyymmdd") & " FROM MyTable_EXTRACT"
    .SetWarnings True
End With
0
Comment
Question by:donnie91910
  • 5
  • 3
  • 2
10 Comments
 

Author Comment

by:donnie91910
ID: 38768269
I would like it to have the date on the end as:
MyTable_20130111_10:38:00 PM. (or whatever time that it is at the time of the copy).
0
 
LVL 13

Assisted Solution

by:LIONKING
LIONKING earned 150 total points
ID: 38768342
Have you tried something like:

Format(Now, "yyyyMMdd hh:mm:ss tt")
0
 

Author Comment

by:donnie91910
ID: 38768492
I when I add the time I get the message:
Run-time error '3067':
Query input must contain at least one table or query.
0
 
LVL 13

Assisted Solution

by:LIONKING
LIONKING earned 150 total points
ID: 38768497
Can you post your code to take a look at it?
0
 
LVL 61

Assisted Solution

by:mbizup
mbizup earned 350 total points
ID: 38768795
See if this makes a difference... it is probably choking on the punctuation (Access is picky about special characters in your object names).

Function BkupLastEntry()
With DoCmd
    .SetWarnings False
    .RunSQL "SELECT * INTO MyTable_" & Format(Now, "yyyymmdd_hhnnssAMPM") & " FROM MyTable_EXTRACT"
    .SetWarnings True
End With

Open in new window

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 61

Accepted Solution

by:
mbizup earned 350 total points
ID: 38768816
If you must have some kind of delimiter to break up your timestamp, use an underscore instead of a colon:

Function BkupLastEntry()
With DoCmd
    .SetWarnings False
    .RunSQL "SELECT * INTO MyTable_" & Format(Now, "yyyymmdd_hh_nn_ss_AMPM") & " FROM MyTable_EXTRACT"
    .SetWarnings True
End With

Open in new window

0
 

Author Comment

by:donnie91910
ID: 38870508
On the "End With" statement, I get the following error:

Compile Error:

Expected End Function
0
 

Author Comment

by:donnie91910
ID: 38872218
Will this code work with Access 2007?
Function BkupLastEntry()
With DoCmd
    .SetWarnings False
    .RunSQL "SELECT * INTO MyTable_" & Format(Now, "yyyymmdd_hh_nn_ss_AMPM") & " FROM MyTable_EXTRACT"
    .SetWarnings True
End With
0
 
LVL 61

Assisted Solution

by:mbizup
mbizup earned 350 total points
ID: 38873017
There is nothing version specific in that code so it should work in any version of Access.
0
 

Author Closing Comment

by:donnie91910
ID: 39032379
This works.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
This video discusses moving either the default database or any database to a new volume.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

758 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

17 Experts available now in Live!

Get 1:1 Help Now