Solved

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

Posted on 2004-08-24
4
270 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

729 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