Question : How to automate the retrieval of data from Access when database name is changing twice a month

Greetings Learned Ones,
I need a best solution answer.
I have a Excel workbook that needs multiple ranges updated with new data from an Access database at least twice a month.
Easy enough to use MS Query in Excel, but THE PROBLEM IS:
Everytime the database is updated from the mainframe, it's database name changes.  The names of the tables/reports/queries in the database stay the same.
What is the best approach to solve this problem?
     A.   A VBA macro in the database to save it to a standardized name and location?
     B.   What would that code look like?  I haven't written any VBA in Access.
     C.   Or is there another simplier solution?
Thanks,
Roddd

Answer : How to automate the retrieval of data from Access when database name is changing twice a month

This is the code that creates a new database file and copies all tables (excluding system and linked tables)  into the new file.

However this topic is rather for the Access zone than Excell

DenisK
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
Sub SaveAs()
Dim appAccess As Application
Dim tdf As TableDef
Dim strNewDB As String 
strNewDB = "path\to\your_fixed_name.mdb" 'path and filename of the new database 
If Dir(strNewDB) <> "" Then
    'delete  new database if already exists
    Kill strNewDB
End If 
'open new Access app and create new database
Set appAccess = CreateObject("Access.Application")
appAccess.NewCurrentDatabase strNewDB
'close app
appAccess.CloseCurrentDatabase
Set appAccess = Nothing 
'loop through all tables in this database and insert into the new database
For Each tdf In CurrentDb.TableDefs
    If tdf.Attributes = 0 Then   'skip system tables
        CurrentDb.Execute ("SELECT * INTO " & tdf.Name & " IN """ & strNewDB & """ FROM " & tdf.Name & ";")
    End If
Next tdf 
End Sub
Random Solutions  
 
programming4us programming4us