Solved

Adding time to a copied table

Posted on 2013-01-11
10
151 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
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.

 
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

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

This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

895 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