Solved

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

Posted on 2004-08-24
4
269 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 50

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Outlook VBA question - How do I mark a message as read 2 59
Microsoft Access 32-bit or 64-bit? 11 58
SUBFORM on ACCESS 2013 8 33
Tabbed form question 5 18
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

734 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