Solved

NEED TO AUTO INCREMENT FILE NAMES WHILE SAVING TABLES IN A MACRO

Posted on 2004-08-24
4
265 Views
Last Modified: 2012-05-05
Hi.  I am trying to find a way to Auto Increment or use the Current date when saving or copying tables in an Access Macro.
I have a macro that does the following:

1.) COPY OBJECT:
    a.) Destination Database: _____blank________
    b.) New Name: Results Copy
    c.) Source Object Type: Table
    d.) Source Object Name: MEETING RESULTS

2.) DELETE OBJECT:
    a:) Object Type: Table
    b.) Object Name: MEETING RESULTS

3.) OpenQuery:
    a:) Query Name: LAPTOP DATA QUERY
    B.) View: Datasheet
    c.) Read Only


 *********This query is a Make Table query that creates a table named: Meeting Results.  I want this table saved with a unique name if possible, or renamed prior to the DELETE OBJECT step in the Macro. The Copy Object name "Results Copy" was created so I would not lose the previous results, but I want to retain ALL previous Results... I would love for the file name to be: Meeting Results XXYYZZ, where XX is the Month, YY is the Day, and ZZ is the two digit year.  If this isn't possible, it could simply be Meeting Results01, 02, 03, etc..

Of importance however, is that I run a report based on the "Meeting Results" table generated in the Make Table Query.  The final step of the Macro is to Generate the report, so I need to be sure that the OpenReport statement will point to the most recent Table..

Thanks!!!! The faster the better!!
0
Comment
Question by:InDashMP3
  • 2
4 Comments
 
LVL 12

Expert Comment

by:fulscher
ID: 11884267
You probably should rewrite your Macros to VBA.

Public Sub SaveTable()
  Dim TableName As String
 
  TableName = "Meeting Results " & Now
  DoCmd.TransferDatabase acExport, , , acTable, "Meeting Reports", TableName, False, False
End Sub

This will create a new table as a copy of the table "Meeting Reports" with the current date as the table name.  

I don't believe that I understood your other requirements though. Could you explain a bit more?

Jan
0
 
LVL 49

Accepted Solution

by:
Gustav Brock earned 500 total points
ID: 11885397
Try this change:

    b.) New Name: ="Meeting Results " & Format(Date(),"mmddyy")

Your second request cannot be done in a macro.
But you could copy your newly created and dated table to a third table with a fixed name like "Meeting Results View" and base your query on this table. Kind of a "shoemaker solution" as we call it here ... but it will work.

I'll leave it to you to write that macro line ...

/gustav
 
0
 
LVL 27

Expert Comment

by:jjafferr
ID: 11885412
Hi ,

Add the following to the Table name and the Report name:
Format(Date(), "MM,DD,YY")

so
if you create your Table like this:
DoCmd.RunSQL ("CREATE TABLE " & "Meeting Results" & " ([A] Text,[B] Text,[C] Text,[D] Integer);")
change it to
DoCmd.RunSQL ("CREATE TABLE " & "Meeting Results " & Format(Date(), "MM,DD,YY") & " ([A] Text,[B] Text,[C] Text,[D] Integer);")

You will have to explain the Report part "OpenReport statement will point to the most recent Table"


I hope this helps.

jaffer
0
 
LVL 27

Expert Comment

by:jjafferr
ID: 11885435
Hey gustav

Great minds think alike, but one minute later. LOL

jaffer
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

776 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