Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need code to get directory and link to specific tables!!! 2

Status
Not open for further replies.

DCBBB

IS-IT--Management
Aug 22, 2001
33
US
I need help writing the code that will search a specific directory and find the latest version of a file and then link to that file (which will either be a .dbf or .xls). Also, I guess I would need to delete the old tables first, which would be linked to the previous version. The naming convention for these files is something like "sales0903" where the "0903' represents the date the file was created (yes, it stinks that the file name changes each week!). I think I have to use the Dir and DoCmd.Transfer commands, but I don't know how to make sure I pull in the latest version. I can hack my way through basic subs but this is beyond my expertise. Thanks!
D


 
Make reference to the Microsoft Office Object library,(MSO97.DLL for 97, MSO09.DLL for 2000) and use the file search method.
Code:
'code above
With Application.FileSearch
    .NewSearch
    .LookIn = "Path"
    .SearchSubFolders = True
    .FileName = "Enter Criteeia here"
    .FileType = msoFileTypeDatabases
            If .Execute() > 0 Then
            'Code for found files
            End If
End With
'code below
Tyrone Lumley
augerinn@gte.net
 
Following function delete links from your DB. You can point DB what links you want to delete or delete all links:

Public Sub LinksDelete(Optional strConnectString As String = "")
'If strConnectString is omitted all links will be removed
Dim tdf As TableDef

For Each tdf In CurrentDb.TableDefs
If tdf.Connect <> &quot;&quot; Then
'Check for linked tables
'Check for pointed links

If InStr(1, tdf.Connect, strConnectString, vbTextCompare) > 0 Then
'Removing links
DoCmd.DeleteObject acTable, tdf.Name
End If
End If
Next tdf
End Sub


Example:
[/b]'Removing links to &quot;C:\Temp\MyDB.mdb&quot;
'if its exist

strNewLinkPath = &quot;C:\Temp\MyDB.mdb&quot;
call LinksDelete(strNewLinkPath)


Aivars


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top