• ** There has been a recent site upgrade. Please clear your browser cache to avoid issues. **
  • New forum feature - post voting and best solution

    Check out this thread for the details: https://www.access-programmers.co.uk/forums/threads/new-forum-feature-post-voting-and-best-answer.314134/

    This new feature looks great to me! :)

  • We now have 3 forum themes

    Go for the default (light) theme, Shades of Grey or Shades of Blue. I just added the Blue one.

    The thread about it is here: https://www.access-programmers.co.uk/forums/threads/new-forum-theme-shades-of-blue.314136/

Macro To Run Saved Imports and Code (1 Viewer)

robsmith

New member
Local time
Today, 21:52
Joined
Feb 17, 2020
Messages
9
Hi,

I am trying to put together a macro to run various saved imports followed by some code. I have done the saved imports and they work but I can't seem to get the code to run.

The code is in a module and I have included it below. Can anyone point me in the right direction?

Thanks

Code:
Option Compare Database
Option Explicit

Sub ImportMatches()
10        On Error GoTo ImportMatches_Error
20    Debug.Print "Deleting current contents of table Matches @ " & Now
30    CurrentDb.Execute "Delete * from Matches;", dbFailOnError
40    DoEvents  'a short break to the OS
50    Debug.Print "Starting to process the Matches csv file @ " & Now
60    DoCmd.TransferText acImportDelim, "OImportSpecification", "Matches", "E:\Documents\Matches.csv", True
70    Debug.Print "Finished importing the csv"
80    DoEvents 'a short break to the OS
90    CurrentDb.Execute "UPDATE Matches SET Matches.ConvDate = CDate(Date)", dbFailOnError
100   Debug.Print "Finished updating the Date on table Matches"
110   Debug.Print "All done @ " & Now
      
120       On Error GoTo 0
ImportMatches_Exit:
 DoCmd.Close acTable, "wMatches"
 'DoCmd.CloseDatabase   'commented out the close database
130       Exit Sub

ImportMatches_Error:
140       MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure ImportMatches, line " & Erl & "."
150       GoTo ImportMatches_Exit
End Sub
 

Gasman

Enthusiastic Amateur
Local time
Today, 21:52
Joined
Sep 21, 2011
Messages
6,869
So what does it do/not do?
 

arnelgp

error reading drive A:
Local time
, 05:52
Joined
May 7, 2009
Messages
10,627
do you import from same csv to same table?
if so you can use the "ImportExportSpecification" itself to execute:

dim oSpec As ImportExportSpecification
Set oSpec = CurrentProject.ImportExportSpecifications.Item("OImportSpecification")
oSpec.Execute
Set oSpec = Nothing
 

Users who are viewing this thread

Top Bottom